Global well-posedness to the 2D Cauchy problem of nonhomogeneous heat conducting Navier-Stokes and magnetohydrodynamic equations with vacuum at infinity