|MadSci Network: Astronomy|
That's actually a more complicated question than it sounds (or an easy one, if I misunderstood you).
When we talk about the temperature of air (or water), what we're really referring to is the average energy of the molecules. In astronomical terms, our atmosphere is fairly dense, and so the molecules collide with each other often and reach equilibrium. By equilibrium, I mean that they have just the energy that they want to have, given the sunlight and other factors to which they're exposed.
Space is a very different place. Most of space is a near vacuum, and so there are very few molecules for us to even talk about having a temperature. Also, because of the low densities, atoms and molecules don't collide very often, and can be far from equilibrium. For example, the atoms in the Solar Wind which pass by the Earth have very high energies, typical of the Solar corona (over a million degrees Kelvin). This is not an equilibrium temperature; the atoms were given that energy when they left the Sun, and just haven't had a chance to lose it.
(Let me make a brief aside here on temperatures. Like all astronomers, I use the Kelvin temperature scale. It's similar to Celsius in that there are 100 degrees between the freezing and boiling points of water, but the zero point is different. It is set so that 0 Kelvin (0 K = -273 C) is absolute zero, the point at which no heat at all is present.)
If you were moving around in the Solar System you would experience temperature very differently from the way we do on Earth. How hot you would be would depend upon whether or not you were exposed to sunlight, and how far away from the Sun you were. Look at Mercury as an example of what happens without an atmosphere. We can measure the temperature of Mercury's surface. The surface temperature of the soil of Mercury is determined by how much sunlight it absorbs and how rapidly it can radiate that energy back into space. On the sunlit side, the soil temperature is over 700 K, while on the night side, it gets to as low as 90 K. Extreme differences like this between sun-facing and shadowed sides are typical for interplanetary space.
There are places in interstellar space where you can talk about temperature in the same sense in which we think of it on Earth. Emission nebulae are one example (the Orion Nebula is a good example of one of these). These are dense (by astronomical standards) gas clouds, heated by nearby hot stars. The gas in them typically has temperatures of up to 10,000 K! There are also even denser dark clouds. They are so dense that their interiors can be shielded from external starlight, and can be extremely cold in their centers, as cold as 10K.
The coldest temperature that anything can realistically reach is 3 K. This is the temperature of the cosmic microwave background radiation (CMB). Because the CMB permeates all of space, and can penetrate even dense gas clouds, essentially everything is exposed to it. So, if no other heat sources are present, gas will come into equilibrium with the CMB.
So, as you can see, there is no one temperature for space. The temperature that you read, about 40 K, is pretty cold for anything in the inner Solar System. It is, however, about right for the extreme outer planets, and is close to the temperature of the surface of Pluto (which it reaches in the same way as Mercury, by balancing heating by sunlight with re-emission back into space).
Try the links in the MadSci Library for more information on Astronomy.