Free Books
I always recommend checking out your public library, but sometimes that's not enough to scratch your book itch. Therefore, here are some sites you can use to get free books in a legal way. Most of these offer multiple formats, including .epub and the option to read online.
Public Domain
Project Gutenberg - lots of books. There are typos and editing issues sometimes, but their formatting works fine.Standard Ebooks - carefully designed and proofread. I love this site!
Faded Page - more books.
Project Gutenberg Australia - books that are in the public domain in Australia.
Project Gutenberg Canada - books that are in the public domain in Canada.
Mobile Read - lots of helpful discussions and tutorials for reading and making ebooks. There's a large library section with public domain texts assembled by users, including some I haven't seen elsewhere.
Archive.org - most books are scans, so formats like epub are just automatically generated from OCR and not very readable. I recommend getting the pdf format instead. There are also books not in the public domain, which you can borrow for a limited time.
Hathi Trust - digitised books, mostly page scans. It can be a bit hit-or-miss in terms of what's fully available, what requires an account, and what's search-only.
National libraries and museums - some countries' national libraries as well as museums offer things like scans of older books and other documents. An example of this is Gallica, provided by the French National Library.
Open Access
Open Access books (and journals) are often copyrighted (the actual license may vary) but they're made available free of charge. Most are scholarly works but there are some literary texts (such as translations) made available in this way.The actual file types depend on the publisher; some are available only as .pdf, while others exist as .epub, html pages, and so on. If you're interested in a specific book, I recommend looking it up on these directories and on a publisher's individual site, as it's happened to me to find more options when looking directly at the latter.
These are sites that compile OA books but they may not be 100% complete. It's a good idea to look into publishers' sites, as many institutions offer open access books.
Directory of Open Access Books - what it says on the tin.
OAPEN - another directory/network.