In Photoshop CS5 or later, load your images into layers.
Select Edit > Auto Align Layers (at macro distances even on a tripod small changes in focus will alter the perspective of each shot)
Select Edit > Auto Blend Layers. This will select the sharpest parts of each layer and create a mask. The masks can be quite complex, but it does a very good job.
There is an open source program CombineZP