There could be a failure in the idle speed advance system. Usually the air conditioner compressor is activated when the heat is turned on. The idle speed needs to increased slightly to compensate for the extra load. If you have a 4 cylinder engine, is is more sensitive to extra load at idle. There could be a vacuum leak in the heater control system but, this usually causes the engine to idle faster and the computer will adjust it somewhat. Try turning the air conditioner on and see if the same problem occurs