I suspect you'll have misfire codes for the cylinders, and a code for an oxygen sensor, or fuel trim. Depending on the scanner used, you'll either have a generic code, or a BMW specific one.
If you have an O2 cell fault, a mechanic should know the O2 cell MAY not be at fault - If you're talking about the M54 in the 530i, it's most likely a vacuum leak - most common is the intake boot. Running too lean (because of the leak), gives an O2, or fuel trim fault.