I have written a local history book that I plan to distribute through KDP. But I would also like to distribute some ebook copies to my local libraries so they can lend them out like physical books. Can this be done through KDP?
No, it's done through Overdrive. I think you have to have 25 books before they'll sign you on. (Draft2Digital also distributes through Overdrive.) Then the library must buy the book. And few local libraries actually have a digital collection, unless they're big cities. In my state, for example, it's a consortium managed by the state library. (And they do have a lot of local interest books, but in a national series.)
(Don't trust KDP to publish a print edition. Don't trust CreateSpace to publish an ebook. Each does one thing well and the other thing poorly.)