What you are experiencing is most likely a misfire, when the CEL is flashing it is going into a protective mode to prevent further damage to the car. When the CEL is flashing you will experience rough idle feeling like the car is bogging down on you and loss of power. When the CEL is not flashing it will be driveable but best thing to do would just be to call a tow truck and tow it back to town. You'll have to diagnose the misfire one by one since it's like finding a needle in a hay stack. It could be fuel related, ignition related as far as the gas cap being loose no that would't causes this significant of a problem.