A new method of calculating total energies of solids and atoms using nonlocal pseudopotentials in conjunction with the variational quantum Monte Carlo approach is presented in detail. The many-electron wave function is of the form of a Jastrow exponential factor multiplying a Slater determinant. By using pseudopotentials, the large fluctuations of the energies in the core region of the atoms which occur in quantum Monte Carlo all-electron calculations are avoided. The method is applied to calculate the binding energy and structural properties of diamond, graphite, and silicon. The results are in excellent agreement with experiment. Excellent results are also obtained for the electron affinities and ionization potentials of the carbon and silicon atoms.