epub is basically a simple variant of html that uses xml to deal with chapters and assets. You zip the whole bundle up and rename it and bam! epub!
http://blog.threepress.org/ is probably the best and most useful resource for learning about this sorta thing, half of the stuff is random tech and the other half is stuff to get it done.
another thing: amazon's kindlegen is actually a great resource if you're targeting that platform. You can generate a mobi file pretty easily and their example is actually incredibly resource-rich.
But really, the whole thing is just a webpage wrapper with limited css and no js, so go nuts and have fun.