This is an old thread, but I wanted to chime in if it could help any body. I had a rough idle twice in the 15+ years I've had my 05' mazda3 with 140k miles.. the first one was due to the gas cap(the springloaded vent failed on the cap)-which was replaced under warranty.
The second time I had a rough idle some codes showed(can't recall at the moment), I noticed it was happening when the engine would warm up, turned out it was the thermostat being stuck so I replaced it. In addition, I put in some fuel injection cleaner in the gas tank and ran it hard/took it out on the highway for 15+ minutes, rough idling went away.
So for those who have tried what others have mentioned, you might want to consider your gas cap, thermostat(especially if it's happening once the engine warms up and your temps look wonky), or even some fuel injection cleaner(maybe with a fill of premium fuel too, I used Berryman B12 btw, great stuff) and running it on the highway.
As of now my driver side motor mount seems to be busted so I get engine vibration, but my idle is normal. I'll replace the mount soon, and eventually I'll probably do what others have done just to give the car a nice "tune up"(Purge selenoid valve, Throttle body cleaning, etc.).