How do planes benefit from flying in formation?
Energy saving

The wing creates lift, which is upward force on the wing. According to principle of action and reaction, there must be a downward force acting on the air. This force creates a downwash behind the wing. As the accelerated air interacts with the still air further away it turns to the sides and back up, creating a slight upwash outside of the wingtips.

Flying in this upwash adds a bit of lift on the next flying thing which in turn means it can fly at slightly lower angle of attack and have less induced drag. This recovers some energy from the wake vortex that would otherwise be dissipated as heat.

Birds

Migratory birds use the typical V formation to take advantage of this, each bird flying aft and to the side of the previous. Since the leader is not getting any advantage, the birds usually take turns in leading the flock.

Aircraft

I have however not heard of this being done with aircraft for energy purposes beyond experiments. Military aircraft usually use similar V formation, but for different reasons. They need to fly in group, because they need to provide mutual defence. And then the V formation is used during cruise to and from target area simply because in it the wingmen see the leader while remaining clear of their downwash and wake turbulence.