If I build an insulated box around the batteries and the system, will it generate enough heat throughout the winter? There is a possibility of -40 or colder.
Lead acid will tolerate -40F if fully charged. If discharged they will freeze at 20F. Even if you have the charge controller in the box it won't make enough heat to help much. As MisterSandals said you can't charge LiFePo4 below 32F but -40 won't harm them.
I think the usual recommendation is to dig a hole below the frost line and keep your batteries there (and well insulated). It sounds drastic but -40F is pretty drastic.
I think agms would be ok .
they don’t discharge much in the cold @ 0 or -15 out side my battery’s stay around 47o if being cycled every day .
I have a insulated box in the garage
So they don’t sit out side