When the check engine light is on, have the engine trouble codes pulled and post them below in the comments. Just about any local auto parts store will do this for free. There is a good chance that an engine sensor is failing. Therefore it is difficult to pinpoint without the codes. When the check engine light is not on then the most likely cause is either bad gas or an engine misfire. A rough idle can be due to a large vacuum leak while the vehicle operates just fine at other times.
The misfire diagnostic may indicate a fault due to a temporary fault not necessarily caused by a vehicle emission system malfunction. Possible malfunctions include the following conditions:
- Contaminated fuel
- Running out of fuel
- Fuel fouled spark plugs
- Basic engine fault