Oh my what a can of worms this one is.
The best hands down is closed cell foam which has a higher R-Value per inch, air seals and prevents moisture transfer.
- This is the only product that can be used where moisture might be an issue. With that said moisture should not be an issue in either of those places assuming everything else was done properly.
- On the safety aspect many people will point to its chemical composition and off gassing and deem it unsafe. While it is true that it does off-gas, a properly installed foam quickly off gasses and there should be none after curing.
- The other major safety aspect with foam is fire. In many cases I say the concerns are overblown because if you are still in the house when it ignites you aren't going to know it.
- With that said, foam must be covered unless it meets certain flammability & smoke ratings.
Open cell foam has the same safety issues as closed cell and while it does have some good air sealing qualities, that can easily be reached with dense packed cellulose which also has the same R-Value.
Dense packed / sprayed in cellulose is generally deemed the best option for those not wishing to go with foam. There is some concern with the borates & retardants used but once sealed into the cavities it isn't an issue.
If I was building a new stick-frame house, I would probably opt for foam boards on the outside (2 layers, offset & taped) with dense packed cellulose for the walls.
- If I was going with a "hot roof system" it definitely would be closed cell foam.
- If I was going for a traditional vented attic it would be cellulose fully air sealed with baffles running from the soffit up to the ridge.
Almost any product properly installed will give you good results - the biggest catch is getting them installed properly which is why those are my top choices.
For more information:
Read "Do you recommend bio-based soy foam insulation?" a Q&A answered by Andy Ault.
Also, check Rick Goyette's Q&A "Should we use open cell or closed cell SPF insulation on the underside of our attic roof in southeast Louisiana?"