318is dies while idling/driving and bucks
So I replaced the engine in my 97 318is with a stock M44 engine (1.9) about 3 months ago, and this problem just started happening.
The other day I was on my home from work going about 35MPH and the car started bucking. I pulled into the parking lot, shut it off, and started it back up. I drove around the parking lot and it was bucking again. I checked my battery and my positive cable is connected via a stereo terminal and it was a bit loose. I tightened it back up and disconnected the negative so the ECU can "recalibrate" hoping that was it.
The car still did it in the parking lot after that, but I gambled and drove home. It was totally fine. I thought it was a hiccup and then I remembered I usually fill it with 89 (which is what the sticker recommends), but the last time I put in a half a tank of 87. That gas was just about burned off and I filled it halfway with premium fuel.
The fuel filter is probably 3 years old (and over a year and a half the car sat while I put in the engine, long time I know). I replaced it today and started it up, and let it idle for a bit. It was totally fine, but then it just randomly died about 5-10 minutes later. It always starts back up without any problem though.
I took it for a spin around the block and it seemed fine, but then it started to buck and the throttle was unresponsive, and then it kicked back in and drove normal again.
When it idles or stalls out, it always starts back up fine.
-My o2 sensor is damaged slightly ( I think I had it still connected while removing the exhaust by accident, but it's been working for 3 months) Maybe it just gave out?
-Bad fuel pump? Do bad fuel pumps give "blips" or when they go bad, they are done for?
Can someone point me in the right direction? Money is very tight right now and I cant afford to be throwing parts on it hoping to fix the problem.
Note: While revving it in neutral, idle to about 3K RPMS seems to be a bit rough. It's not a smooth rev.