How much do you have to pay for a retest in CA?
How old are your plugs, rotor and cap?
How long since your last oil change?
You are pretty close... Fresh oil is always a good idea for an emissions test... and you might want to inspect the plugs, rotor and cap if they are fowled up they could make the difference... and might solve your rough idle to boot.
If the O2 sensor is working you dont want to replace, it would be a waste at this point until you know if your sparks are clean and strong.
If you have a multi meter with duty cycle you might want to check out this recent thread by LeaUK:
O2 sensor test and inverse duty cycle
who also has an M119 engine and tested duty cycle to ensure proper range of opperation at the X11 test connector. This will give you a peek into the system and might be able to either rule out or suggest the O2 sensor.