The O2 sensor is a good place to start. Also nnsure that the cold start valve isn't leaking. That will also cause you to have a hard time passing your smog testing. You may also end up having to change out the catalytic converter.
Hi NOx is from running too lean. There is a way to adjust the AFM so that there is more fuel delivered to run richer and lower the NOx. Do a google search for AFM adjustment and you'll find the information you need.
To reset the Service Indicator lights, jumper in pin 1 to pin 7 on your diagnostic connector. Do this with the key turned off. After you jumper the two pins, turn the ignition to ACC without starting the car. keep it there for 3 seconds to reset the oil lights and 9 seconds to reset the service lights. Here's a URL with a pic of the diagnostic connector.
http://www.unofficialbmw.com/images/reset1.gif