I use Batch Image Resizer. It can batch-process hundreds of images quickly. It has autocrop action where it can automatically remove uniform or semi-uniform "background" from the sides you specify.
You can play around with tolerance to achieve optimal results. Here's the screenshot of that (all 4 sides are selected):

It is a commercial product though it's not very expensive and they frequently have sales.
Disclaimer: I have purchased this product sometime ago and am its paid user.
EDIT:
Sorry did not pay attention to "gratis" tag at first. In that case I would also say ImageMagick, though it is certainly not as straight forward to use as the software I mentioned.