The motorway will become a "hydrogen highway" so motorists can use alternatives to petrol and diesel.
Drivers of electric and hydrogen-powered vehicles will be catered for at refuelling and recharging points as part of plans to boost the renewable energy industry and create jobs.
South Wales is the latest region to become one of the UK Government's Low Carbon Economic Areas (LCEA), with a focus on hydrogen as an alternative to conventional fossil fuels.
Ministers said they wanted the M4 to have the UK's biggest low carbon refuelling infrastructure.
There are plans to include other regions, with similar filling points proposed for Swindon, London and the Midlands.
It is hoped providing electric charging stops, hydrogen, compressed natural gas and bio-methane filling points will help stimulate the market.
The Assembly Government, which is supporting the scheme, said opportunities to test vehicles running on renewable technology would be available as the motor industry looks for ways to cut carbon emissions.
Ministers said they want to stimulate the growth of an industry supply chain within South Wales to create environmentally-friendly jobs and training to meet demand in the future.
Talks with car makers and bus operators are under way about bringing research projects to Wales.
The University of Glamorgan is investing £6.3 million in hydrogen energy research, including at a hydrogen combustion engine test site at Baglan, just off the M4 in Neath Port Talbot.
Welsh Secretary Peter Hain said the plans would support economic recovery and become integral to Wales prospering in the future.
"Hydrogen presents exciting opportunities for low carbon energy and I want South Wales to become a UK centre of excellence and expertise in hydrogen fuel technologies in both research and development and manufacturing," he said.
"There are enormous opportunities to be exploited from clean, reliable hydrogen power.
"By designating this LCEA in South Wales, we are able to capitalise on existing expertise and skills that will bring economic advantages to Wales, and the rest of the UK."
Get environmentally friendly at our Big Green Switch website
Deputy First Minister Ieuan Wyn Jones said: "It will position Wales globally as a leading centre for driving forward this technology and provide us with a competitive advantage when attracting new investment and research and development into next generation technologies."
Environment Minister Jane Davidson said: "This would be of great help in meeting our challenging targets for reducing greenhouse gas emissions, increasing the amount of energy we derive from renewable sources and improving the security of fuel supplies."
Friends of the Earth Cymru director Gordon James said: "While greening transport is important, it is also essential that major efforts are made to reduce our dependence on cars by improving public transport, cycling and walking facilities."
Ian Williamson, vice chairman of industry body the UK Hydrogen Association, said: "Investment in hydrogen transport infrastructure is an absolute necessity if the UK is to meet its carbon reduction goals and there is a real opportunity for the UK to become a world leader in this technology."