I've used spray foam. Be aware the cleanup from Great Stuff and expanding urethane foams is difficult to downright awful. Latex foams (such as Dap) have water cleanup. They expand from the can like shaving cream, and stay that way, and stop drafts (though not so much pests).
The duct seal putty makes a good exterior covering. Or use a good elastomeric caulk.