I'll publish another post detailing my toolchain, but here's the overview.
I wrote the book using Markdown and styled the PDF with CSS using PrinceXML. The kitabu framework (http://github.com/jstorimer/kitabu) held it all together and automated the translation to different formats.
In the beginning I had to dive into the different formats to get them all working as I wanted but now I've got that automated.