Have a Car Question? Ask a Mechanic Online.
I think you're already looking along the right lines as this does sound like a loose / poor electrical connection, I'd check the wiring and connection to the major engine sensors so the; airflow meter on the intake pipe, the crank position sensor on the engine block, the oxygen sensors mounted on the exhaust and the throttle position sensor.
If all of these are OK ( unplug each in turn and check for corroded contacts and bad wiring) then also check the condition of the wiring loom where it passes under the other components and where it passes through the bulkhead. Under the fusebox is good spot to confirm that the loom hasn't fretted / rubbed through and its earthing on the body