Millions of residents in four Australian states and territories are bracing for heatwave conditions, with temperatures to rocket to more than 40C.