I'd start by checking the resistance of the spark plug leads ( 13-15Kohm / metre) and replace if any doubt or high resistance - Also replace the spark plugs if any of them fail this checklist:
Then check all the connections to the engine sensors one at a time, remove each one and examine for signs of corrosion or damage and a squirt of contact cleaner ( not WD40) will also help.
This could be an airleak after the airflow meter, any air dragged in here isn't 'seen' by the ECU and so not compensated for and leans the engine out causing rough running.
Check the hose clips for tightness and inspect the trunking for any cracks or splits and also all the vacuum system, the small bore pipes and fittings for cracks and missing parts.
The best way to locate a leak is to have the engine running and warm and then spray lighter gas around each joint in turn. If the engine rev's up you've found your leak.
Work your way through each possible joint one at a time and you should find it. I use a slightly flattened piece of brake pipe and some rubber hose from the can of lighter gas to provide a spraying 'wand' and allow a direct blast of gas into each area, especially those difficult to reach with large implements.
Air leaks are very temperature dependent as gaps can open or close up as things expand with heat, so they can be effected by the weather and engine temperature.
This leads them to be quite intermittent in the case of mild leaks
It’s also worth getting the fuel pressure checked as if this is low due to a blocked filter or faulty regulator or even a poorly pump will all result in insufficient fuel being delivered to the engine
Also check the ECU power supply (fuse and relay) and those for the fuel pump supply and also the connections to the crankshaft speed sensor.