First problem's first. A flashing check engine light means that something is wrong that could damage your engine. Others here are correct, it's probably a spark plug or coil pack issue triggering the light. A loose or fouled plug won't ignite the cylinder when cold, but when the engine has warmed up can have just enough spark to ignite and run the cylinder. If you have more than one doing this, then you could cause some damage. This can be cause by several things, but the easiest to check and replace are the spark plug wires and spark plugs. On the newer Grand AM & Prix cars, they use a solid state ignition and instead of a single coil, they use a coil pack. The coil packs usually don't go bad, but can.
Take it to someplace like Autozone that will read the codes from the car computer and print them out for you. The description they print out is usually pretty decent, but allow the person to go into a little more detail, but take it with a grain of salt until you verify it. I would expect to see a code similar to P0301, P0302, etc. The P30x codes are usually misfire codes and the last number should reflect which cylinder is misfiring. You may have several codes.
When you go to replace your spark plugs, make sure the engine is cool, and do one plug and one wire at a time. Pick one to start with, remove the spark plug wire, then the spark plug, double check your gap on the new plug, and carefully install the new spark plug. You don't want to over tighten it, but you don't want to have it took loose either. Solidly snug is an apt term. Although this may the time to buy a cheaper torque wrench and learn how to set it. The torque value should be specified in the manual. Then match the old spark plug wire up to a new one to find the correct length and install the new wire. Repeat for the other cylinders.
When you are all done, start the car and take notice if it behaves the same way and if the check engine light is still flashing.