  We present a theory and a calculation scheme of structural optimization at
finite temperatures within the quasiharmonic approximation (QHA). The theory is
based on an efficient scheme of updating the interatomic force constants with
the change of crystal structures, which we call the IFC renormalization. The
cell shape and the atomic coordinates are treated equally and simultaneously
optimized. We apply the theory to the thermal expansion and the pyroelectricity
of wurtzite GaN and ZnO, which accurately reproduces the experimentally
observed behaviors. Furthermore, we point out a general scheme to obtain
correct $T$ dependence at the lowest order in constrained optimizations that
reduce the number of effective degrees of freedom, which is helpful to perform
efficient QHA calculations with little sacrificing accuracy. We show that the
scheme works properly for GaN and ZnO by comparing with the optimization of all
the degrees of freedom.
