I've generated a spreadsheet to calculate the cost and profit of upgrading and improving mines, taking into account both normal and slow (to the right) speed, the lost resources while improving, the heroes speed-up bonus to reduce that time and the research bonus given from research buildings, as well as the costs of having to pay to demolish and improve.

If you want me to calculate with this any queries then I can do. Here are a few thoughts though from trying a few examples.

The better your research building the more important improvements are.
The cost of upgrading a mine is normally recovered within a few days.
The cost of improving a mine is normally recovered within a few weeks.
However it normally takes a month+ for improving to pay off over upgrading (the time difference between the two the upgraded mine has still been generating resources).
At very high levels it is cheaper to pay full price than slow down an improvement (due to the longer time of lost high level resources).
A high upgraded but lowly improved building can be surprisingly quick to repay to demolish and rebuild.
There is very, very little difference in time between upgrading a few levels and upgrading just one.