Styrofoam is extruded polystyrene foam. The cell structure is closed not open. I'm not a chemist, so take that into account, but it's not the first thing I would think of using. If it works however and you have some clean stuff, it probably is ok.
Most styrofoam is actually polystyrene. There's some evidence that styrene can have adverse health effects - it accumulates in fatty tissues and may have neurotoxic and carcinogenic effects in some animals.
As far as I know, no has really studied the effects in fish, and I'm guessing small amounts probably aren't a problem (I've had polystyrene backgrounds in a bunch of my tanks), but I'd be wary of using it as a filtration media where you're constantly pushing water through it and promoting it's breakdown.