That's just weird and intermittent problems are hard to diagnose...
If it were bad coolant temp sesor it would start fine and flood as it warms up.
EGR is closed when idleing and closed when started, if it were faulty it would run bad all the time = vacuum leak.
O2 sensor has no role when starting cold.
Only thing I can think of that plays a role there is MAP sesor. As you turn the key past on to start it takes a Barometric reading, so if it does not get one then? But if you restart without turning key off it has a reading to start with... is there a wiring issue that MAP does not get power key on? Only run? Map sensors hardly fail and when they do it is always. Can also check MAP reading with scan tool. Could even be fauly ECM although they hardly ever fail at this age without human interference.
Surging idles biggest cause is vacuum leak, but restart does not cure it.
That's a tuff one.