I think you might get some help for this by looking through the wiki such as
this page. There are links there to some software like ebook-tidy, which might be the kinds of things you are looking for.
The only way to achieve perfection though is the painstaking way, I'm afraid. (Not in Word though. Word pretty much always gives you junk.) Still maybe that's not necessary here.