Harvesting Energy Through Thermoelectrics: Optimizing Nanomaterials for Power Generation and Cooling