Characterizing temperature and strain variations with qubit ensembles for their robust coherence protection