A method is presented for the optimization of one-body and inhomogeneous two-body terms in correlated electronic wave functions of Jastrow-Slater type. The most general form of inhomogeneous correlation term which is compatible with crystal symmetry is used, and the energy is minimized with respect to all parameters using a rapidly convergent iterative approach, based on a Monte Carlo sampling of the energy and a fitting of energy fluctuations. The energy minimization is performed exactly within statistical sampling error for the energy derivatives, and the resulting one- and two-body terms of the wave function are found to be well determined. The largest calculations performed require the optimization of over 3000 parameters. The inhomogeneous two-electron correlation terms are calculated for diamond and rhombohedral graphite. The optimal terms in diamond are found to be approximately homogeneous and isotropic over all ranges of electron separation, but exhibit some inhomogeneity at short and intermediate ranges, whereas those in graphite are found to be homogeneous at short range, but inhomogeneous and anisotropic at intermediate- and long-range electron separations.