How can the black body radiation formula be so general? In the derivation of the black body radiation formula, there is nothing whatsoever that relates to a particular/specific material. But we nonetheless use this formula for several distinct sources in nature, such as the Sun and the CMB.
How can it be applicable to so many different things?
As far as I understand, the emitted photons come from the rotational and vibrational levels.
But shouldn't these levels depend on the particular material/elements that the object is made of? 
Summarising:


*

*Is the black body radiation formula applicable to an macroscopic object composed of different elements only? 

*How can it describe so different things (eg Sun spectrum, CMB) if there is nothing in the formula that relates to a specific material/element?

*If the photons come from vibrational/rotational levels transitions, shouldn't these depend on the object in question? Also, what's the actual reason why there are no contributions from translational motion? And what about excited electrons?
 A: 

How can [the blackbody radiation formula] describe so different things (eg Sun spectrum, CMB) if there is nothing in the formula that relates to a specific material/element?


Answer: 


In the derivation of the black body radiation formula, there is nothing whatsoever that relates to a particular/specific material.


Any result that doesn't pay attention to a particular quality / quantity during the derivation is independent of that attribute. This supposes that both the initial assumptions and derivation are correct (enough).
Physicists split energy transfer into a variety of independent categories which may all be calculated in isolation and added together for an accurate model of reality. The black body radiation equation describes energy transfer by photon emission of the object. The emission spectrum from the sun gives a good approximation of the surface temperature, but it also shows slight variation from this simple model.


Shouldn't [the rotational and vibrational levels of the emitted photons] depend on the particular material/elements that the object is made of? Is the black body radiation formula applicable to a macroscopic object composed of different elements only?


Macroscopic, warm objects exhibit so many geometries and have so much free energy that they present a continuous spectrum, and the model fits very well. As bodies gets smaller, purer, more isotropic and colder, they exhibit more effects from discrete energy levels. Both purity and size relate to the emission spectrum similarly, though the sun (pure but large) and many crystals (impure but small) demonstrate these imperfections.


Also, what's the actual reason why there are no contributions from translational motion? And what about excited electrons?


It's important to note that photons come off of the object from the change in energy (rotation, vibration, energy level and translation). Atoms in solids do not have translational motion compared to the other atoms in the solid.
A: The black body formula applies exclusively to a perfectly black material. The thermal spectrum of a real emitter is, as you expect, a complex function of its material properties. A perfectly reflective metal surface, for instance, would not emit any thermal radiation, at all, and colored materials are predominantly emitting at those wavelengths, at which they are good absorbers. 
When physicists make a decision about the assumptions for a model, they usually make a reasonable trade-off between acceptable model errors and the difficulty of the calculation. For some calculations it is perfectly acceptable to model the radiation of stars as black body radiation. For stellar spectroscopy, of course, one would use a detailed atomic emission and absorption model and for molecular clouds one has to use the proper molecular spectra. 
A: This is an excellent question, one that was dealt with by physicists in the previous century by means of the following argument. 
Suppose for the moment you have two bodies in thermal equilibrium at the same temperature $T$, and let us also suppose for the moment that they emit electromagnetic radiation with different spectra, depending for instance on their physical characteristics. 
Suppose also, that between wavelengths $\lambda_1$ and $\lambda_2$ , body 1 emits more than body 2. Now place the two bodies inside two boxes, and open a small hole allowing EM to pass between them. Also insert a filter which allows passage only of radiation with wavelengths in the range $\lambda_1 \leq \lambda \leq \lambda_2$. This way, body 1 will lose energy, which will be gained by body 2. 
After an infinitesimal amount of time, body 2 will be slightly warmer than body 1, but for some time the passage of EM will continue.
What have we achieved this way? A thermodynamical transformation whose only result is to transfer heat from a cooler body to a warmer one. 
We have thus violated the second principle of thermodynamics. Thus the contraption above must be impossible, and the only way to prevent this, if the two bodies have initially the same temperature, is to deduce that the spectrum of emitted radiation is the same for all bodies in thermal equilibrium at the same temperature. 
Thus the black body spectrum is generated by any body in thermal equilibrium, be it large like the Sun or small like the water in your coffee-making machine. 
A: Both in practice and in theory, the best way to get a black body spectrum is to make a small hole in the wall of a hot cavity.  Any light entering the hole will probably bounce around many times, and eventually be absorbed, before it could leave the cavity.
The invariance of the spectrum follows from the Second Law of Thermodynamics.  (This argument doesn't give any insight to the mechanisms, but is nevertheless enlightening.)  Two cavities, made of different materials but at the same temperature, face each other.  All the radiation from one enters the other and vice versa.  If their total emitted radiation was different, there would be a net flow of energy from one to the other - which is forbidden by the Second Law (and the Zeroth law too, for that matter).  If the total radiation was the same, but the spectra were different, you could come up with a simple scheme such as placing a bandpass filter between them, to make sure that if body A emits more than body B at a specific wavelength, only that wavelength is allowed through, still causing energy to pass from A to B.
Your questions, @CuriousOne:

Is the black body radiation formula applicable to an macroscopic object composed of different elements only?

It is applicable to any body, but only if it is actually black at all wavelengths.  A microscopic object can also be a black body.  For example, a plasma consisting of one free proton and one electron inside a perfectly reflecting box with a small hole is a black body.  (See later answer for details.)

How can it describe so different things (eg Sun spectrum, CMB) if there is nothing in the formula that relates to a specific material/element?

As long as there is some mechanism of generating photons of any required wavelength, thermodynamics will see to it that such photons are generated in the required numbers.  If there is no such mechanism, the body will not be black.  For example, if you found a material that was completely transparent to green light because it had no atoms capable of absorbing green light, then this body would not generate the green part of the black body spectrum - because it is not black.
The one-electron plasma I mentioned would be OK because the free electron can have any energy, and can therefore emit and absorb at any wavelength.

If the photons come from vibrational/rotational levels transitions, shouldn't these depend on the object in question? 

See previous answer.  

Also, what's the actual reason why there are no contributions from translational motion? And what about excited electrons?

Whenever free electrons are present, they will contribute to the emitted radiation through their translational motion.  In a plasma, this mechanism is called bremsstrahlung.  In a metal, it is called reflection.  In an atom, emission can only occur if an electron is excited.  An atom in the ground state cannot emit.  A molecule can emit even if there is no electronic excitation, because it also has vibrational and rotational levels.
A: The answer lies in the many available states. The radiation comes from a large number of electronic/vibrational/rotational states. While these are different for different materials in aggregate for a macroscopic material there will always be some combination of states that gives a specific energy.
A: Black body radiation, is of course the radiation of a black body. However, it is related to the radiation in a void with almost any kind of wall, not just black. The thermal radiation inside the void is assumed to be in thermal equilibrium with its walls. The number of photons inside at a particular mode, wavelength and radiation pattern, will be independent of the properties of the walls. If the walls emit a certain mode poorly, then by time reversal symmetry it will also absorb this mode poorly. So if the walls are black or not is not important as long as it is at all possible to emit radiation in all the modes. 
If the walls are black they will absorb all the radiation that falls onto it. If the walls are in the thermal equilibrium with the walls, then they will radiate equally much at all wavelengths. Now, if we have a little hole in the walls of the void. The radiation that goes through hole will be identical to the radiation of a black wall.
In this situation molecules will not only emit at the wavelengths that we think of as their spectra. First of all, we should consider doppler shifts due to a thermal velocity distribution. Additionally, there will non resonant scattering of photons which will alter the wavelengths of the photons. Similar arguments apply to how solid wall will produce photons at all wavelengths.
When you consider CMB we are actually inside the void. The sun spectrum is emitted from a plasma where charges run around and interact with each. Such a system will be able to emit light in any wavelength and therefore also absorb light at any wavelength.
It is easy to believe that the suns surface would more easily emit certain wavelengths, but then if light of such a wavelength is produced somewhat deeper inside that light will not come out because it will be absorbed on its way out. On the other hand light that less easily emitted is also less easily absorbed and will therefore come from a thicker layer of the suns surface. This can compensate for many such deviations in the elementary emission mechanisms.
For sufficiently small objects the argument why the sun will black in spite of different emission mechanisms will not apply. Objects with only a couple of constituents will not be black. They can only emit light at some discrete set of wavelengths in their own system. Replace the small system with a square box of the same volume. Pick a few relevant mass values and calculate the spectra for each and combine them. This will constitute a generic system. It will have spacing between the states which gives transition energies. At temperature $T$ it typically populates states with excitation energy unto a few $kT$. The possible absorptions lines for photons of energy of a less than a few $kT$, is a discrete set. If the typical thermal doppler shifts are small they will not smear out the absorption spectra, and if it does, then a small object will at best be grey, not black. It will semitransparent.  
A: The answer to this question primarily lies in the perception of what black-body radiation is. You must look at it not from the point of view of the source generating the radiation, but from the radiation as an object (or rather "gas") itself. What Plank's distribution talks of is the statistics of a collection of photons at equilibrium. So, in order to allow this, we have the following assumptions that go into this description.


*

*Photons are massless spin-1 bosons and follow Bose-Einstein statistics. (This assumption is largely irrelevant to the question, but I decided to put it in, for completeness sake).

*The chemical potential for thermal photons is zero, implying that the number of photons in the system is not conserved.

*The gas itself is assumed to be non-interacting, so each photon remains essentially free. In reality, this works very well as photons, under regular conditions do not interact very much with other photons. There is an interaction present at much higher energies, called Delbruck scattering, but the scattering cross section is rather small and inconsequential for considerations of thermal photons at low energies. Another subtle point to understand here is that the source of radiation plays a secondary passive role as it serves only as a infinite reservoir of photons of all wavelength. In that sense, though the photons are non-interacting amongst themselves, they do "interact" with the wall of the source as they can be absorbed or emitted even at equilibrium.  


To reiterate what @akrasia and others have said previously, as long as the body is capable to generate radiation at all wavelengths, then given a fixed temperature of the system, the photon statistics upon equilibration will be a geometric distribution for photon number and the intensity variation will b given by the Planck law. It does not matter how the photons were generated and it is precisely these processes that encode the material specific properties. As with any other system in thermodynamic equilibrium, the rates of production or absorption or re-emission of photons are irrelevant at the point of equilibrium. Hence as long as any system satisfies the above assumptions, the distribution is going to be the same.
A: The black-body spectrum is one subject of statistics. We want to use statistics to back up thermodynamics. As we understand it, thermodynamics studies objects that are in the so-called thermal equilibrium, which highly restricted the possible states and the distribution of these states the objects (systems) are in. This requirement makes the microscopic states of the object/system irrelevant. What is left is fully determined by the quantity called temperature. That is why the black-body spectra of different systems look the same. In fact, Boltzmann distribution, Fermi-Dirac distribution and Bose-Einstein distribution are all the same for different systems. 
