EFI? check the crank angle sensor....had mine come loose one time. Engine was erratic and unresponsive. Timing was advancing and retarding seemingly at random. Seems to help when its bolted down.

Anyway, that's one thing to check.
Also, while engine is "almost dieing" fiddle around with the wiring harness...wiggle things. if wiggling a wire makes the engine run better (or worse) you could get a better idea where to start looking.
Intermittent problems are the worst....I wish you luck.