Your IAC valve may be clogged up when this happens the motor doesnt get air at idle when the throttle body butterfly is closed at idle .The IAC valve is soliniode opperated when the soliniode is open ,it opens when the TPS sensor senses that the butter fly in the throttle body is closed the soliniode opens and the motor gets air through it .