We propose an exactly solvable lattice Hamiltonian model of topological phases in 3+1 dimensions, based on a generic finite group G and a 4-cocycle ω over G. We show that our model has topologically protected degenerate ground states and obtain the formula of its ground state degeneracy on the 3-torus. In particular, the ground state spectrum implies the existence of purely three-dimensional looplike quasi-excitations specified by two nontrivial flux indices and one charge index. We also construct other nontrivial topological observables of the model, namely the SL(3,Z) generators as the modular S and T matrices of the ground states, which yield a set of topological quantum numbers classified by ω and quantities derived from ω. Our model fulfills a Hamiltonian extension of the 3+1-dimensional Dijkgraaf-Witten topological gauge theory with a gauge group G. This work is presented to be accessible for a wide range of physicists and mathematicians.