You might try cleaning the idle air control valve. My 2002 Elantra had an erratic idle, I took the idle air control valve off, and found that it had some build up in it. I took it off, cleaned it out and sprayed a lilttle lubricant in it, and I have had no idle problems since then. Its right by the throttle position sensor, has 2 bolts and 1 electrical connector on it. The valve should move easily by hand, if it doesn't that might be your problem.