This is actually very easy to do with ImageMagick.
I recently wrote a little utility faviconbuild which I have released on github under the MIT Open Source license.
This is a link to the shell script I wrote for Unix / Mac (and Windows if you use Cygwin). I also provide a bat file for anyone on Windows. I would like to encourage anyone to contribute to the project as well, including feature requests. You can read more about it on the project page and I have also included a link to download the ImageMagick binaries I was using during development.
There is a subroutine named createIcon where I do the work, but here is a short example of using ImageMagick directly to package different source files into a .ico file.
convert "image1.png" "image2.png" "image3.png" "result.ico"
The website also has some other usage examples such as the one found here.
convert image.png -bordercolor white -border 0 \
\( -clone 0 -resize 16x16 \) \
\( -clone 0 -resize 32x32 \) \
\( -clone 0 -resize 48x48 \) \
\( -clone 0 -resize 64x64 \) \
-delete 0 -alpha off -colors 256 favicon.ico
This does the work of resizing an image and creating an icon with one line of script (or multiline with the \ character at the end of the line). Obviously this one liner doesn't give you the option to pick and choose the source image per size though.
I have also published a blog post on the development that serves as a mini tutorial for batch/bash for those interested.