Those are the catalyitc converters and the reason they are probably rattling is that the steelwool between them and the actual heat shield itself has fallen out.
If your cats are rotted - thats fairly expensive job - although u could buy a used set - no guarantees though.
There has been a DIY for this, here is the link - have to do this on my car as well.
http://www.dvatp.com/bmw/maintenance/e36/2004/06/05