You have at least two separate problems here. The first is the error code suggesting the camshafts are out of phase (retarded). This is often the result of the cam-chain having stretched and requiring replacement. Fundamentally, once the chain stretches, the on-board computer detects this and illuminates the check-engine light as well as logging the fault code. If this is the case, the repairs could easily run into the thousands. However, it could also be a fault with the sensor that reads the camshaft position or something else altogether, but the timing chain would be the prime suspect. It could also cause a slow idle such as you've noted.
The second problem is that the check-engine light was either broken or deliberately disabled to disguise the fault with the cam-chain. I'm certainly not accusing the seller of doing this, but it can't be ruled out. And yes, an illuminated check-engine light is a roadworthy item, so the car would (or should) not have passed a roadworthy inspection with the lamp illuminated.
Whether the roadworthy tester is at fault will come down to whether they knew the check-engine light was faulty or not. Of course, if the light was already broken when the car was presented for inspection, that would muddy the waters further.
I sincerely hope you bought the car from a licensed car dealer and not a private seller. If it was the latter, you'll have little to no chance of gaining compensation for what could be a very expensive problem. But if you bought the car from a dealer, then you should have some come-back, especially once you prove that the check-engine light was either broken or disabled at the time you inspected the car prior to purchase. That's partly because of Australian consumer laws as well as the fact that the dealer needs to provide the roadworthy certificate and is responsible for its accuracy.