Why does my iPhone heat when charged and when in use
1. Bad Connection
In areas with poor or reduced connectivity, iPhone has to expend more time searching for and maintaining network connections. This in turn uses more energy which causes the battery to heat up.
Possible Solution
You can try turning Airplane Mode on and see if you have the same problem with heating up.  I also have an iPhone and I myself notice that it does not heat up if I am out in the open, but it heats up and drains the battery if I am in the basement of a large concrete building.
2. Case?
If you have a case for your iPhone, you should expect that it heats up. The case, while it does protect your phone, also blocks some air from coming out and consequently causes the hot air to be trapped inside the phone. This will cause your iPhone to heat up almost indefinitely.
Possible Solution
When you are charging your iPhone, take it out of its case. While this may be inconvenient, it will help.
3. CPU Usage
If your phone is heating up, you may have a lot of applications open. Also, if you were playing a lot of games, then you can expect an increase in CPU usage and temperature as well.
All of the listed items below can contribute to an increase in CPU Usage:

Games
Data Usage (Facebook, Emails)
Fetch/Push Data

Possible Solutions

Do a Network Connections Reset (Go to Settings =&gt; General =&gt; Reset =&gt; Reset Network Settings, then reboot (you will lose WiFi passwords)

Try disabling the following apps (in Settings =&gt; General =&gt; Restrictions): Multiplayer Games, Ping, App Store, iTunes Store. Then reboot.


4. Defect
If nothing else works, then it is also quite possible that your iPhone is defective and if this continues to occur as you have stated, I would take it to an Apple Store. They may be able to better diagnose the problem.
Links and Resources
MacRumours
Apple Discussion Board
Apple Discussion Board