If it is a closed cell foam, then yes it is water proof.
Be careful though as you can alter the sound of your speaker by adding foam directly behind a speaker, think of speaker baffles, great idea but they really do hinder the performance of the speaker.
Car audio speakers are meant to get wet, every car leaks water in the doors, it is just a fact of life, some more than others.