On the minimization of residual thermal stresses in viscoplastic materials