Stepwise process for the sustainable recovery of rare metals and earth elements