Any NPC can have a spell book for sale, but the ones I mentioned are more likely to have them.

If you quick save before running your mouse over an item/chest/merchant or hitting the alt key, you can identify the item or trade with the merchant, then quick load to get different stats or inventory. This can be done repeatedly to get the best stats or specific bonuses on an item (save after finding good candidates) or looking for specific items (such as spell books or charms) from merchants. Don't waste too much time with this, though, it really isn't necessary to get the best possible equipment.
After talking to an NPC, it takes awhile for their inventory to be reset (varies between NPCs, but generally around 10 or 15 minutes real time).