The optimization problems involving local unitary and local contraction matrices and some Hermitian structures have been concedered in this paper. We establish a set of explicit formulas for calculating the maximal and minimal values of the ranks and inertias of the matrices X1X1* - P-1, X2X2* -P-1, X3X3* - P-2 and X4X4* - P-2, with respect to X-1, X-2, X-3 and X-4 respectively, where P-1 is an element of C-n1xn1, P-2 is an element of C-n2xn2 are given, X-1,X-2,X-3 and X-4 are submatrices in a general common solution X to the paire of matrix equations AX = C, XB = D.