Is there a way to delete unneeded keyframes automatically? I made an animation by keying every bone in the rig on every keyframe.

Now I have a lot of extra keyframes, as some bones didn't move at all, remaining the same for all keyframes.

Is there a way to delete these extra keyframes automatically?
And are there any "good practices" to help prevent this happening?
Yes you can. 

In the Dope Sheet, select all channels by pressing A while hovering over the list of channels, then press O. All unnecessary keyframes will be erased.