We theoretically investigate trapping conditions for ultracold polar molecules in optical lattices, when external magnetic and electric fields are simultaneously applied. Our results are based on an accurate electronic-structure calculation of the polar $^{23}$Na$^{40}$K polar molecule in its absolute ground state combined with a calculation of its rovibrational-hyperfine motion. We find that an electric field strength of $5.26(15)$ kV/cm and an angle of $54.7^circ$ between this field and the polarization of the optical laser lead to a trapping design for $^{23}$Na$^{40}$K molecules where decoherences due laser-intensity fluctuations and fluctuations in the direction of its polarization are kept to a minimum. One standard deviation systematic and statistical uncertainties are given in parenthesis. Under such conditions pairs of hyperfine-rotational states of $v=0$ molecules, used to induce tunable dipole-dipole interactions between them, experience ultrastable, matching trapping forces.