Sounds like a loose wire/dodgy earth. Best way through this is to think about what exactly could be causing the behaviour you describe, and work from there...
Don't think it will be a vac pipe, because I can't see how that would be intermittent? A pipe is either split or it's not - it doesn't keep switching from okay to split!
A fuel pump problem is a possibility, but would this cause the car to cut out altogether?
I would suspect that it's ECU related - either the ECU itself, a frayed wire to one of the sensors or a faulty sensor. The engine still runs, albeit retarded, so I'd hazard a guess that something is feeding the ECU duff (or rather no) information. Without information from all of its sensors, the ECU goes into safe (sluggish) mode and retards the timing becuase it doesn't know what's going on!
I would check the operation and wiring to the following components:
Blue Temp sender (as already mentioned...) - allows the ECU to adjust the fuel mix if the engine is cold. Note that the timing will be retarded if this isn't working, regardless of the actual engine temp (as the ECU doesn't know what the temp is!). This is on the coolant hose entering the front of the head (there's a blue one and a black one - the blue one is for the ECU, the black one is for the temp gauge in the dash). When it's working okay, there's usually an audible difference in the idle when you disconnect it with the car running. Clean the plug contacts, and check the condition of the wiring all the way back to the ECU. Replacing the blue sensor itself is always a good idea anyway.
Knock Sensor - allows the ECU to adjust the timing to account for knocking. This is on the left-side as you look at the engine, on the front - can't remember if it's at the top of the block, or the bottom of the cylinder head :embarassed: Again, the engine will run retarded if no signal is received from the knock sensor, so check the wiring.
Airflow Sensor (AFM/MAF) - informs the ECU of how much air is being let into the engine (by measuring the position of the intake flap). Check the wiring is okay, and there's a procedure of how to test the AFM itself in Haynes. Don't think it will be this will be at fault, unless there's an intermittent fault from within the unit.
If it's none of these, check the earths for the ECU, and as a last resort, swap your ECU. When you've found and fixed the problem, it probably wouldn't hurt to get your CO set and work through rubjohnny's tuning guide.