Mg2NiH4 is a promising hydrogen storage material with fast (de)hydrogenation kinetics. Its hydrogen desorption enthalpy, however, is too large for practical applications. In this paper we study the effects of transition metal doping by first-principles density functional theory calculations. We show that the hydrogen desorption enthalpy can be reduced by ~0.1 eV/H2 if one in eight Ni atoms is replaced by Cu or Fe. Replacing Ni by Co atoms, however, increases the hydrogen desorption enthalpy. We study the thermodynamic stability of the dopants in the hydrogenated and dehydrogenated phases. Doping with Co or Cu leads to marginally stable compounds, whereas doping with Fe leads to an unstable compound. The optical response of Mg2NiH4 is also substantially affected by doping. The optical gap in Mg2NiH4 is ~1.7 eV. Doping with Co, Fe or Cu leads to impurity bands that reduce the optical gap by up to 0.5 eV.