Hey I'm just trying to help:)
So you have a stock M42 with AFM. Ebay chips can sometimes be complete garbage and you have no idea what you're getting. In post #3 you say you switched the ECU? I agree that a lot of parts are interchangeable, but you have to kinda stick with 4-4cyl and 6-6cyl unless you're doing custom stuff. One, two or many things can cause your symptoms..... your O2 sensor, and now you have multiple issues due to a bad O2 sensor. A bad sensor will trigger your check engine light, give you a rough idle and surging. Did you by any chance unplug your AFM and forget to plug it back in? You're AFM not working correctly can give all symptoms also. Ryann can also be correct in that this just happened at the same time as something else and they are completely unrelated.
I would go back to your stock chip as you said that you have and start checking outside of that. If you can find another #175 ECU try that too. Check your connections on the AFM and the O2 sensor. That's where I would start.
HTH,
Cheers,
Ralph