Second Law Of Thermodynamics says every closed system loses energy (technically: the entropy of a closed system can only increase). Recycling Humans (or anything) to feed more Humans will lose energy at each generation. In the case of Humans a lot of energy because Humans are really bad at making electricity.
The Sun obscured by clouds in The Matrix is still heating and warming the Earth, its only the direct solar energy that is blocked. This still leaves several ways of harnessing the Sun's power.
If the Sun were completely gone, there remain many, many reserves of power on the Earth. Vsauce covers this in his video "What If The Sun Disappeared".
- Geothermal (which will last billions of years)
- Fission and fusion
- Chemical (far more than just oil)
What about using a Human as a battery? Humans are very bad at converting calories into electricity and produce less than a volt. But a battery is just an energy storage unit, usually chemical. Humans have lots of chemical energy stored inside them! That's what a calorie measures. You'd be better off using Humans as a source of chemical energy: burn them. You'll get about 75000 Watt-hours out of burning an adult Human which is enough to keep a laptop running for about 1000 hours. At 7 billion humans that's 525 trillion Watt-hours or 1/7th of the electricity produced in the US per year. Use that to produce steam to turn a turbine to generate electricity (which is what we do today). Then whatever you planned on feeding the humans, burn that, too!
Don't get too excited by those numbers, converting power from one form to another is inefficient (again with the Second Law). It depends on how you do the conversion, but theoretical limits are in the 60% to 80% range. Reality is more like 40%.
When it does make sense to use Humans for power is to recapture the waste energy of going about your daily life. From exercise equipment with generators on them, to a self winding watch. In this sense, you are using the chemical energy stored in a Human as a battery, converting it to kinetic energy, and then converting that to electricity. This isn't using Humans to generate energy, it's capturing what would have otherwise been lost by normal Human activity.