Spaceflight presents unusual challenges to storing and collecting electrical power. Electrical power is required to operate instruments and support equipment. In addition to the modest power requirements of computing, communications, and sensing electronics, some spacecraft components require large amounts of electrical power. Large peak power levels allow for radars to achieve better range or penetration through materials. It can also be used for propulsion in the form of ion drives, which improve efficiency over regular rockets by separating the storage of energy from the storage of reaction mass.
Most satellites in Earth orbit are powered by solar arrays. These are large, but they can be folded up at launch and deployed on orbit. Photovoltaic technology has seen rapid development in recent years. For operation beyond Earth, the reduced intensity of light from the sun means that spacecraft must have larger solar arrays, which can introduce several disadvantages. The mass of solar panels is mass that cannot be used for payloads, and the increased vehicle mass requires more powerful maneuvering systems (jets and reaction wheels). Large solar arrays may be viable for operation in the outer solar system, but with significant disadvantages compared to RTGs (see below).  Solar panels can be made with safe, readily available materials, while RTGs require fuels that are difficult to safely handle and which are in limited and highly regulated supply. The Mars Exploration Rovers (Spirit and Opportunity) obtained all their electrical power from solar panels. There was concern early in the mission that the lifetime of the rovers would be limited by dust accumulating on the rovers, but the dust was periodically removed by wind, leaving mechanical failure as the only limiting factor in the rovers' lifetimes. 
Probes that travel a long distance from the sun often use radioisotope thermoelectric generators (RTGs). These devices contain pellets of a radioactive material, often Plutonium, which produces heat from radioactive decay. Thermocouples convert some of this heat into electric power. The radiation from the fuel is not used by RTGs, but there are designs for devices which can produce electricity by capturing beta particles. 
The principle advantage of an RTG over a solar array is that the RTG works in any environment for a very long time. The Voyager probes, currently the most distant artificial objects, are both powered by RTGs and are still operating, albeit with the loss of some instruments.  RTGs have no moving parts and are very simple: fundamentally, they consist of a fuel cell, thermocouples, and shielding. The output of an RTG decreases over time due to decay of the heat source and degradation of the semiconductor thermocouples from radiation.
In contrast to the earlier Mars Exploration Rovers, the Mars Curiosity rover usese an RTG to generate its electrical power. It also has a lithium-ion battery pack which is recharged by the RTG to support large transient loads. The rover can operate at night, or it can use large amounts of power during the day and recharge the battery at night.
RTGs are very inefficient: Curiosity's RTG produces 2000W of thermal power but only about 120W of electrical power. The extra heat is dissipated by fins. This large amount of waste heat adds engineering challenges that other power sources don't face: even when electrical power from the RTG is not being used, it still produces full thermal power which must be dumped into the environment. During transport and assembly on Earth, cooling systems must be provided to keep the RTG at an acceptable temperature.
The presence of radioactive material in an RTG means that safety is a major design consideration. Modern RTGs are designed to survive a launch failure or re-entry without dispersing their fuel. There is little radiation risk from an intact RTG. In fact, a few manned missions have included one. Apollo missions 12-17 carried an RTG as part of an experiment to be left on the moon, and one fell to earth when Apollo 13 returned with its lunar module descent stage. This RTG fell into a deep trench in the Pacific ocean and is currently believed to be intact. 
Apollo and the space shuttle both used hydrogen-oxygen fuel cells for electrical power. Fuel cells combine two chemical components at a controlled rate to produce heat, electricity, and some chemical waste product. In the case of hydrogen-oxygen fuel cells, this waste produce is water, which could be used by the crew.
Fuel cells require significant support equipment which adds significant weight and introduces potential failure modes. The two fuels must be stored in tanks, cryogenically for hydrogen and oxygen. The fuels are delivered to the fuel cells by plumbing and valves which could fail mechanically. The famous failure of Apollo 13 was caused by an explosion of an oxygen tank supplying fuel cells and breathable air to the crew.  This single point of failure severely reduced electrical power to the spacecraft and endangered the crew due to a limited supply of breathable oxygen.
Fuel cells share the advantage with RTGs of operating without the need for sunlight, but the fuel is consumed quickly. While an RTG may operate continuously for decades, a fuel cell may deplete its fuel supply in days under normal operation. Unlike RTGs, fuel cells use safe materials and their reaction rate can be controlled to limit waste heat. The poor energy-to-mass ratio of fuel cell systems may limit their applicability to near-Earth manned spacecraft, where a supply of oxygen is already needed and the waste water can be put to use.
Non-rechargeable batteries are not viable on most spacecraft as a primary power source, although some small amateur satellites have used primary cells for short missions. They have been used on some spacecraft for special purposes: Curiosity's descent stage used thermal batteries, and the Apollo missions used batteries to power re-entry systems after the service module containing the fuel cells was jettisoned.
Rechargeable batteries are important for load levelling. They are commonly used on satellites to provide continuous power while the satellite moves in and out of sunlight. Curiosity uses a rechargeable lithium-ion battery pack to power large temporary loads while the rover's RTG provides a lower, constant amount of power.
Research into more efficent solar panels is ongoing, primarily for providing power on Earth. The future of RTGs is in question due to the limited supply of fuel, but NASA is investigating producing small quantities of Pu-238 for space missions. Radioisotope-powered Stirling engines are a possible improvement to current RTGs. Like RTGs, such an engine uses a block of radioactive material as a heat source, but instead of thermocouples it uses a heat engine to operate a generator. It promises to be more efficient than an RTG, but with increased complexity. A prototype has been built, but none have been launched. 
© Ben Johnson. The author grants permission to copy, distribute and display this work in unaltered form, with attribution to the author, for noncommercial purposes only. All other rights, including commercial rights, are reserved to the author.
 M. F. Piszczor et al., "Advanced Solar Cell and Array Technology For NASA Deep Space Missions," Prof. 33rd IEEE Photovoltaic Specialists Conference, (PVSC '08), 11 May 08.
 P. M. Stella et al., "Managing PV Power on Mars - MER Rovers," Proc. 34th IEEE Photovoltaic Specialists Conference (PVSC '09), 7 Jun 09, p. 001073.
 R. Bao, P. J. Brand and D. B. Chrisey, "Performance of Radiation-Hardened High-Efficiency Si Space Solar Cells," IEEE Trans. Electron Devices 59, 1286 (2012).
 R. P. Rudd, J. C. Hall, G. L. Spradlin, "The Voyager Interstellar Mission", Acta Astronautica 40, 383 (1997).
 G. R. Schmidt, R. D. Abelson and R. L. Wiley, "Benefit of Small Radioisotope Power Systems for NASA Exploration Missions", AIP Conf. Proc. 746, 295 (2005).
 "Report of the Apollo 13 Review Board," U.S. National Aeronautics and Space Administration, June 1970.
 J. Chan, J. G. Wood and J. G. Schreiber, "Development of Advanced Stirling Radioisotope Generator for Space Exploration," U.S. National Aeronautics and Space Administration, NASA/TM-2007-214806, May 2007.
 N. Nguyen, "Space Propulsion Technology and Energy Expenditures", Physics 240, Stanford University, Fall 2011.
 S. Kumar, "Energy From Radioactivity", Physics 240, Stanford University, Fall 2011.