Well, whatever the reason machines keep humans alive, it is definitely NOT because of humans' excellence in the role of batteries. However it is possible that the machines themselves are spreading that myth. (For example Morpheus would believe anything the Oracle says). That machines don't really need humans for power is revealed in the last part, when the Architect agrees to free all humans from the Matrix.
The actual reasons may be much more complicated, and much more humane. The machines just don't want humans to become extinct, just like we humans are trying to protect Siberian tigers, as well as other endangered species. Even though a tiger may kill a human given the chance.
However protecting humans is much harder than the tigers. You can't put them in a cage, because then their minds will degrade. You can't let them roam free, because they probably won't survive in the new world, or because they will probably keep trying to fight the machines until they kill themselves. Humans aren't very rational, you see.
As a solution, the tandem Matrix - Zion was created. The Matrix is conveniently situated right next to the Zion so that people in Zion can focus the majority of their energy in "freeing" others from the Matrix. Also, quite conveniently, the Matrix lacks any real defense mechanisms.
If there was just Zion without the Matrix, the humans would be trying to develop nuclear weapons or EMP bombs in order to launch the assault on the machines. Obviously they would fail, but they will also kill themselves in the attempt.
If there was just Matrix without Zion, then such system would run a risk of collapsing and destroying the humankind if some unforeseen catastrophe occurs. The machines aren't really good at adapting to sudden changes. And they are vulnerable to other unpredictable factors (such as Agent Smith). The machines know that, but they can't do much about it.
Now why do they need to destroy Zion every now and then? Well, first of all they probably don't see it as much of a big deal -- the population of Zion is comparatively low. Plus they want to keep them from acquiring too dangerous technologies. Plus in most cases the goal is not really destruction, but rather the threat of destruction. For example in the last movie, several EMP charges could have destroyed the majority of attackers. The machines know that, and they probably launched the attack with the goal of failing, but making humans more scared. The machines didn't foresee however that Agent Smith would be able to interfere and stop those EMPs.
So in summary, it's all a well-orchestrated plan to keep humans busy, and alive.