I'd use some automotive seam sealer on the gals and seams, you can buy sealer that is clear, some is called clear but is more of a translucent white. Surface needs to be scuffed up a bit, then sealer applied. The 2 part catylizing sealers work best, dry best and hardest. You could also use a bead of windshield urethane, a little bit more flexible and economical. Either will far outlast silicone caulk and set up alot firmer.
I guess the gaps you are talking about are under the bedrail? These body style trucks are the worst yet for the big gaps like that, I don't know that I'd use home spray foam, it tends to deteriorate when exposed to elements, again the automotive industry has nice foam adhesive/ sealers that would work well, their cure time and expansion size varies and they are not cheap. 3m and fusor (Lord) are the ones I know of.
You may also want to look into a rubber tailgate seal that 2 way tapes to the tailgate opening. They don't ever fit perfectly, but they help alot.