In 2014 the country opened the largest wind farm in Africa, valued at $1.4 billion, in the southwest near the city of Tarfaya. Then, in early 2016, it switched on the first facility of the world's largest concentrated solar plant, Noor-1 , on the fringe of the Sahara desert. When completed in 2018, it will power one million homes and make Morocco a solar superpower.

And while the country is still heavily reliant on energy imports (90 percent in 2013, according to the World Bank ), it plans to generate 40 percent of its energy from renewables by 2020.

Following this road has led to Morocco hosting the UN's 2016 summit on climate change, COP22 , in Marrakech. So what lies ahead?

Cutting the energy bill

Morocco ranks seventh in the world in the 2016 Climate Change Performance Index , and is the only non-European country in the top 20.

It's also one of only five countries to have achieved a "sufficient" rating for its efforts to keep warming below 2°C in the Climate Action Tracker (no country has achieved the "role model" rating as of yet, so "sufficient" is currently the best grade).

An aerial view of the solar mirrors at the Noor 1 Concentrated Solar Power plant, 12.5 miles outside the central Moroccan town of Ouarzazate.

How did it get there? "We started with a question: How can we decrease our energy bill?" Said Mouline, director of the National Agency for the Development of Renewable Energy and Energy Efficiency, told CNN.

"Morocco is a very energy dependent country. In 2009, that bill amounted to $10 billion."

So, in 2011, Morocco altered its constitution to include sustainable development, stopped subsidizing fossil fuels to make renewables more competitive, and started welcoming private investments in the clean energy sector.

Efficiency is key

"This transition has two paths, and renewables are just one. The other is energy efficiency. Both need to be developed at the same time," Mouline said.

One key action is reducing waste: the electricity state utility, ONEE, has started a program to replace old incandescent light bulbs in Moroccan households with 10 million compact fluorescent lamps (CFLs), which are far more efficient.

To offset the initial cost -- CFLs are six time more expensive -- the utility allows users to pay for them in installments through the bill, which itself is lowered by the better efficiency.

The United Nations Environment Program estimates that by switching just 40 percent of households, power consumption would drop by 20 percent, cutting 2.74 million tons of CO2 emission by the end of 2021 -- as much as would be created by consuming 308 million gallons of gasoline, according to the EPA Greenhouse Gas Calculator.

As part of its efforts for a greener future, Morocco has also started to transition its 15,000 mosques to renewable energy, and in July it banned the production, sale and use of plastic bags, of which it used three billion each year.

A $3.5 billion economy boost

Mouline, who's also a member of the Steering Committee of COP22, says energy efficiency is the cheapest way for countries to meet their targets under the Paris agreement.

"The government set some ambitious goals. Fifty two percent of our energy capacity must come from renewables by 2030, and by the same date we must achieve 20 percent better energy efficiency in all sectors: transport, housing, agriculture.

The wind farm in Melloussa, 21 miles from Tangiers in northern Morocco, has 165 turbines, with a production capacity of 140 megawatts.

"That means that if our energy consumption doubles by 2030, we want to actually consume 20 percent less than that. We want to stop wasting energy," he said.

And the country could run entirely on green energy by 2050, according to a study by Stanford University on the energy roadmap of 139 countries.

This would contribute about $3.5 billion to the economy and add over 88,000 permanent jobs, the study predicts.

An example for Africa

At an event held at COP22 in 2016 promoting solar energy in Africa, Morocco's efforts were used as an example of how Sub-Saharan Africa can capitalize on the highest irradiation rates in the world, even though solar power only makes up approximately 0.5% of energy production in the area.

The event highlighted the World Bank and International Finance Corporation's efforts to raise $16 billion for solar, hydro, and geothermal energy projects throughout the continent.

According to Mouline, this transition will be inevitable: "We are switching, all over the world. Last year more money was invested in clean energy than fossil fuels for the first time. Look at how many new jobs renewables, energy storage and electric mobility have created."

Morocco's wind farm in Tarfaya, which produces 850MW, has created an new industry in the country, as 70 percent of the spare parts for the turbines are manufactured locally.

"Making electricity is only a part of a larger strategy."

Water security

As a country made up of 78 percent desert or dry zones, according to FAO estimates , Morocco faces special challenges in the fight against climate change.

"At the Earth Summit in Rio in 1992, Morocco was one of the first countries to ratify the agreement on biodiversity, desertification and climate change," said Abdelâdim Lhafi, High Commissioner for Water, Forests and the Fight Against Desertification of Morocco.

"Before 1992 and starting in the 1960s there were strong policies about water, and Morocco now has about 140 dams with a total storage of 18 billion cubic meters (635 billion cubic feet), which is crucial for a country that is severely hit by droughts."

Due to increased demand, demographic changes and tourism, some areas of the country now experience water scarcity: "But we've made a lot of progress in the use of water, especially in agriculture which absorbs 85 percent of our supply. That's why we're looking at new technologies for our 1.2 million hectares of irrigated areas, to preserve our food security," Lhafi said.

"We've done a lot, but we still have a lot to do in the coming years."