Bad idle can be o2 sensor related, but it's most likely an air intake leak, vaccum leak, or idle control valve.
Your idle control valve is a silve cylinder under the intake manifold. It's a real bitch to get out though, but I managed to do it on my car in about an hour, but I ended up bruising my forearms squeezing them under the manifold to pull it out.
I guess the proper way is to remove the intake manifold, but then you get into all sorts of other complications like removing the fuel rail etc....
Try this first though....
Goto canadian tire, and get this stuff called INTAKE MEDIC. It's a spray in a red/black can. Pop off the Idle Control Valve breather hose from your intake boot, and while the car is running, spray a bunch into the tube and it will suck it right through the ICV cleaning it out (hopefully). After squirting, the car will sound like it's about to stall but then recover....rev the engine via the throttle body cable, and repeat until idle surging is gone.
If that doesn't do it, then you'll need to remove the unit and clean it by hand like I had to...the thing has a little flap that opens and closes, and mine was stuck halfway open because it was gummed up. After spraying it a bit with the intake medic, it works like new!
'94 Supercharged E36 325is (150,000 original km's)
-Vortech V9 G-Trim @ ~10psi w/ BOV
-255LPH Walbro fuel pump
-TEIN SS Coilovers w/ Pillowball mounts
-Keskin KT1 17x8.5 & 17x10
-Remus full catback
-Authentic Rieger Infinity I body kit
-SMT6 EMS (Untuned)