HTML to write a book. PrinceXML to generate a PDF out of it. Then calibre for Mac to generate epub/mobi from HTML. I had to edit manually the output from calibre though.
I use Pandoc to generate my EPUB and then Sigil to do a bit of tidying. Usually just the front matter etc.
Some other resources here, the slides from ConFoo are the most up to date http://rachelandrew.co.uk/presentations/css-books