Engine surging at idle

I have a 2003 explorer with a 4.0 SOHC engine and an automatic transmission. After starting, the engine runs smooth, however when I put it in gear(any gear) the engine starts surging. After driving even a short distance and I stop, it idles smooth again until the next time I shut it down and start again. I checked it with a OBD check and it shows everything is OK. Also I noticed when this started happening I hear a metallic rattle just as I start to depress the accelerator pedal. What’s up?

I’d start off by having the idle control valve, throttle and MAF sensor cleaned.

Look for a loose or broken TPS (Throttle Position Sensor).

This can cause intermittent bursts of fuel from the injectors and an unstable idle because the PCM thinks the throttle is moving.

what is the best medium to clean these with. Denatured Alcohol? Carb cleaner?

For the MAF sensor get MAF sensor cleaner (which I think is not really different from typical electronics cleaner - I use each interchangeably). For the IAC you can use carb cleaner or intake cleaner.