Sorry for the late response.
Your problem is most likely a failed or clogged VVT solenoid or VVT actuator. A lack of regular oil changes can clog up these devices.
When a VVT dies, they make a knocking/rattling sound during acceleration and throw the codes you mention.
You can easily check the solenoids for electrical values (should be 5-15 ohms across the 2 pins) as they stick out of the valve covers, but checking the actual solenoids for clogs will require you to pull the valve covers. The actuators are held down by a small bolt and then slide out.
Checking/changing the VVT actuators themselves is a much bigger job involving pulling both the valve covers and timing chain cover. If the vehicle has not yet had its water pump replaced, you should consider doing that at this mileage anyway.
Check out my DIY here and find the section on checking the VVT solenoids for the electrical specs and more info on what's involved in the bigger job.
https://www.mazdas247.com/forum/showthread.php?123860369-CX-9-Water-Pump-Replacement-DIY-Guide
A quick test is to disconnect both VVT solenoid wires and see how it runs. If it smooths out (may still throw codes) then it's likely one or both VVTs. You don't actually need VVTs working to run the vehicle, but it change the power and response characteristics. if you want to run without them, disconnect both.