To generate power using a classic thermodynamic engine, you need to be able to move energy from a high-temperature reservoir to a low-temperature reservoir. And the greater the temperature the difference, the better your efficiency.
Now the surface of Earth is at about 300 K or so, while intergalactic space is about 100 times colder at 3 K (from the cosmic microwave background radiation). So to run an engine for free at high efficiency, all we should have to do is shovel heat energy off the Earth and into deep space.
We can dump energy into space because any object at a reasonable temperature emits radiation, ideally in proportion to its emissivity (close to 1 for black things, nearer 0 for shiny metal) and its temperature to the fourth power. (Stefan-Boltzmann law.) If its surroundings are colder than it is, it receives less radiation back than it radiates itself, and so it cools. This is just what a space radiator does.
Space radiators are already used in spacecraft to deliberately get rid of unwanted heat energy. All you need to do is run some hot fluid through some black-painted pipes facing open space (rather than the Sun), and they will radiate energy in the infra-red while receiving almost nothing back in return from the surrounding stars and space. The fluid will be cooled, and the heat disposed of.
Now imagine one space radiator facing the Sun, and the other into cold space. One will get heated, the other can throw energy away. There is no reason why you couldn't run a closed-cycle engine (e.g. Stirling engine) between the two to obtain free solar power. This should work well on the Moon, especially if you chose a perpetually sunny hillside for the 'hot' end and a shaded crater wall for the 'cold' end. However, such a thing would be unreliable and complicated compared with passive photovoltaic panels. On a satellite or Moon base the last thing you want is unreliable complex systems, so the engine wouldn't be a good idea -- unless it worked out much cheaper or more efficient for very large installations, say.
But could we generate free power like this on Earth? All we have to do is radiate heat into the clear night sky to generate some free "cold". This could be stored in an insulated vat of liquid, to cool things or use for air conditioning; or we could dump heat into it and drive an engine, exploiting the temperature difference between the surroundings and the cold stuff. Or if we could use the cooling power to condense a refrigerant and bottle it up, later gaining work from its expansion back to a gas -- then we can store energy without keeping the stuff cold (just under pressure).
We really could get free energy like this, but unfortunately it wouldn't be too effective or easy. Here are the problems:
For the record, I have tried this experimentally with a low-tech space radiator consisting of a damp bit of old black sock (for high emissivity), supported on a piece of plastic carved from a mineral water bottle, wrapped in foil and suspended in a foil-lined container. The result? It held a temperature about 4 degC cooler than the surrounding air on a clear, calm night. Noticeable, but not really sufficient to do anything useful with.
[1] From http://gamweb.in2p3.fr/~javier/durham_MIRsensing.pdf.