Optimal dynamos in the cores of terrestrial exoplanets: Magnetic field generation and detectability