Say that we have many undead zombies/vampires/ghouls/whatever. I want to use them to generate electricity, because they never get tired, never need to take breaks, and can exert great force without needing large amounts of material inputs. What is the best way to do this? Should I have them ride some sort of stationary bikes attached to generators? What should they be doing with their arms to generate extra electricity?
If your undead are humanoid the best method is to use a treadwheel. It has been used since classical times and is really the best solution. Humans have evolved to walk longer than almost any other animal and treadwheel uses that. Some of that is lost with undead since they do not get tired anyway but it should still be optimal method for humanoid form.
With proper bearings and light weight materials efficiency should be good. Since undead do not breathe or need to take breaks you can optimize the wheel in ways that would kill live humans. Such as replace air with low pressure helium or make the wheel entirely closed without any way to exit.
Just add an electric generator.
EDIT: Forgot to mention.
It is not part of the question but you need to remember that it is still a muscle engine. That means that power density will be inferior to modern power production. That means more volume per watt. Which usually means higher construction cost per watt. Which usually means more expensive electricity.
So you need to either accept that electricity is more expensive and hence used much less or cheap out on construction and accept lower efficiency or build for very long term which only works for more stagnant economy.
Raise the corpses of great authors from the past. Then cover their bodies in magnets and bury them again.
Next step is making movies out of those authors' works, produced and directed by people who have never read them. The authors will forever be spinning in their graves. Due to the magnets, that will work like a dynamo per coffin and with some wiring you will be able to extract energy.
This is not an original idea. It was proposed by Aaron Diaz from the Dresden Codak.
One giant 'water wheel', but instead of water, use the zombies. Herd them into a chute at the top, and they step onto the paddle. They ride the paddle to the ground, just like water would, turning the wheel. When they reach the ground, they get dumped out. Jut herd them back up to the top, and keep the cycle going. The wheel drives whatever device you wish - generator, grinding mill, saw mill, whatever.
No real intelligence necessary, just an unlimited supply of zombies who want to do nothing but walk aimlessly in a herd.
Just as a reminder, the energy that you obtain out of the zombies is the energy they expend in climbing back to the top of the cliff or structure, and then lose again in their descent down the wheel. You would get even more energy if you had them carry rocks or something up to the top, and take them down the wheel.
As always, it depends:
Zombies most likely are not the smartest, so strapping them to a stationary bicycle wont work. This would mean you couldn't have a zombie spin class.
If you have a lot of zombies, that REALLY are relentless, so not just stop moving cause they can't see someone with brains, then you could have something like a giant pressure plate, generating power with movement the zombies make. A company called Pavegen promotes something like that and states that each footstep produces 2 to 4 Joules of power.
To put that in perspective, a Joule per second is a Watt, so you would need around 20 steps per second to power a 60 Watt LED lamp. Assuming a zombie takes a step every 2 seconds, you would need 40 zombies to power just one lamp constantly.
Vampires are problematic, as they still have their own mind and don't just do as they're told. Additionally, they (famously) need food.
If neither of these things are a problem, they could make for a great power cell. In most vampire fiction, they are stronger and faster than a normal human. Wikipedia states in the article about Human Power that a an elite cyclisst can produce close to 400 watts of mechanical power sustained over an hour and in short bursts can sustain power levels of 1000 to 1100 watts.
A vampire should be able to hold twice that intensity, so just one blood sucker could power a small house, with lights, TV, and refrigerator.
Ghouls seem similar to the zombies, but with more control over their actions. In DnD they routinely dig up graves to feed on the body parts. So either they are more active zombies that could power your generators even more effectively (though unlikely to power them directly like a vampire strapped to a bicycle), or they are worse, as they won't move when they see no escape.
Decaying bodies emit methane which could be collected and burned as "unnatural" gas.