After 5 turn grace period of not putting any production into a unit, hammers start decaying at a rate of 1/turn. The 5 grace turns do not necessarily have to be consecutive (e.g. if you pause for 3 turns before continuing the build you would have 2 more grace turns remaining if you paused the build again), and the timer does not reset until the unit is completed [separate timer for each unit type].
Same concept for building except that the grace period is 50 turns.
Same concept for building except that the grace period is 50 turns.