Kayode Odejayi had opened the scoring prior to Gray's double with a Jack Midson penalty and a late controversial Kwesi Appiah header almost helping the Dons claim something out of the game.
A mistake on six minutes by Alan Bennett allowed the home side to open the scoring. On-loan Rotherham striker Odejayi latched onto the loose ball and raced ahead of his marker and tucked the ball into the bottom corner of the net from 15 yards.
It was 2-0 on 19 minutes when young striker Gray got his head to a Will Hatfield corner and it looped into the net.
Appiah glanced a header narrowly wide for the Dons on 24 minutes while Peter Sweeney forced a superb diving save out of Stanley goalkeeper Marcus Bettinelli.
However, it was Stanley who came closest to the third when Gray hit the upright with a 20-yard effort.
That third goal did come just two minutes after the break when, after a Nicky Hunt effort was saved, Gray headed home another Hatfield corner.
Dons boss Neal Ardley made three substitutions as his side looked to get back in it and one of them, Danny Hylton, won a penalty after a foul by Luke Joyce on 74 minutes. Midson slotted home from the spot for his seventh goal of the season.
And, amid late drama, Appiah's header appeared to be cleared off the line, but referee Mark Brown said the ball had crossed the line in the 89th minute. However, there was not enough time left for the visitors and Stanley finished the season on a high.