You said your o2 sensor was aftermarket?
My buddy that works on bmw's told me that aftermarket o2 sensors are crap, they've had too many problems with them.
Try unplugging it. When i would plug mine in it had no power and wouldn't run right until i unplugged it.
Hope you get it running.