From what you said, I would think O2 sensors or that area. They control the fuel trims +/-20% in the ECU. If the PCM is reset, these go to zero. They don't learn until up to temperature, then it's in closed loop learning. Obviously is the mixture goes too far either way then idle troubles will happen. Did you say it seems to run fine when driving? This would then point me in a direction of an exhaust leak before the O2 sensor(s), the amount of air on idle compared with exhaust fumes would be higher than driving so it may affect it more on idle. Does the O2 sensor have a single wire? if so it needs to get an earth to read correct, usually it gets it from the block conducted via the exhaust, if there is corrosion then community could be impacted. Perhaps use an Ohmmeter between the base of the sensor and 0V battery, if this isn't close to zero it will affect the reading from the O2 sensor(s) fooling the ECU.