Normally, when removing a rear wheel, I shift to the small-small combination since this gives the most slack and gets the rear derailleur out the farthest. (Obviously, this doesn't matter for a front wheel). Then, when putting the wheel back on, put it on in the small-small combination and shift out of it when you've tightened the wheel down.
You need to make sure your wheel is seated all the way in the dropout. If you have horizontal dropouts, this means all the way back up to the little set screws which tell you how far back to put the wheel (you don't need to re-set the set screws). For vertical dropouts, this means all the way up in the dropout.
If the wheel was in properly and the gears were aligned before removal from the dropout, they should be still aligned when you put the wheel back in. In the case that the wheel isn't aligned properly, either your derailleur took a hit at some point, the wheel/tire is somehow hitting the brakes, or most likely, you didn't put the wheel in the dropout properly. (I suppose frame damage is also a possibility, but this would have been something you noticed before removing the wheel)
Try re-seating the wheel in the dropout. If you're sure you've got it in the dropout correctly, follow the instructions on adjusting your rear derailleur here.