We present a theory of the electronic structure of GaN/AlN quantum dots (QD's), including built-in strain and electric-field effects. A Green's function technique is developed to calculate the three-dimensional (3D) strain distribution in semiconductor QD structures of arbitrary shape and of wurtzite (hexagonal) crystal symmetry. We derive an analytical expression for the Fourier transform of the QD strain tensor, valid for the case when the elastic constants of the QD and matrix materials are equal. A simple iteration procedure is described, which can treat differences in the elastic constants. An analytical formula is also derived for the Fourier transform of the built-in electrostatic potential, including the strain-induced piezoelectric contribution and a term associated with spontaneous polarization. The QD carrier spectra and wave functions are calculated using a plane-wave expansion method we have developed, and a multiband $\mathbf{k}\ensuremath{\cdot}\mathbf{P}$ model. The method used is very efficient, because the strain and built-in electric fields can be included analytically through their Fourier transforms. We consider in detail the case of GaN/AlN QD's in the shape of truncated hexagonal pyramids. We present the calculated 3D strain and electrostatic potential distributions, the carrier spectra, and wave functions in the QD's. Due to the strong built-in electric field, the holes are localized in the wetting layer just below the QD bottom, while electrons are pushed up to the pyramid top. Both also experience an additional lateral confinement due to the built-in field. We examine the influence of several key factors on the calculated confined state energies. Use of a one-band, effective-mass Hamiltonian overestimates the electron confinement energies by \ensuremath{\sim}100 meV, because of conduction-band nonparabolicity effects. By contrast, a one-band valence Hamiltonian provides good agreement with the calculated multiband ground-state energy. Varying the QD shape has comparatively little effect on the calculated levels, because of the strong lateral built-in electric field. Overall, the transition energies depend most strongly on the assumed built-in electric field. The calculated variation of transition energy with quantum dot size is in good agreement with the available experimental data.