How old were Fred and George when they left Hogwarts, and what year were they in? I’ve been struggling to find out this answer!
They were 18, and in their seventh year.
At the start of Goblet of Fire, when the twins get back to the Burrow after giving Dudley Ton-Tongue Toffee, their mother lays into them and Harry asks Ron what is going on. Ron replies that the twins "didn't get as many O.W.L.s as she expected".
It therefore follows that those tests are what students take at age 15. If they took O.W.L.s in Harry's third year, that would put them two years ahead of him.
Seeing as they leave in Order of the Phoenix (book five) they had to have been in year seven at Hogwarts.
To start year seven, you must be 17, or you wouldn't have been 11 to start year one.
Their date of departure and their birthday (April 1st) suggests that they had already turned 18 at that point.
Fred and George left Hogwarts in their 7th year. We know that at the start of the 5th book, they were 17 years old as they were allowed to do magic outside out Hogwarts.
With two loud cracks, Fred and George, Ron’s elder twin brothers, had materialized out of thin air in the middle of the room. Pigwidgeon twittered more wildly than ever and zoomed off to join Hedwig on top of the wardrobe. “Stop doing that!” Hermione said weakly to the twins, who were as vividly red-haired as Ron, though stockier and slightly shorter. “Hello, Harry,” said George, beaming at him. “We thought we heard your dulcet tones.” “You don’t want to bottle up your anger like that, Harry, let it all out,” said Fred, also beaming. “There might be a couple of people fifty miles away who didn’t hear you.” “You two passed your Apparation tests, then?” asked Harry grumpily.
Harry Potter and the Order of the Phoenix, Chapter 4: Number 12 Grimmauld Place, Page 68
Now, if they left Hogwarts after April 1st, then they would be 18, but I don't think its ever explicitly stated what month they left
In Chapter Twelve of Goblet of Fire we find the following occurring when the Triwizard Tournament is announced on the first day of school:
“They can’t do that!” said George Weasley, who had not joined the crowd moving toward the door, but was standing up and glaring at Dumbledore. “We’re seventeen in April, why can’t we have a shot?”
In Chapter Thirty of Order of the Phoenix, during the time period immediately following Fred and George’s departure, we have the following statement:
The problem was that with just under a month to go until the exams and every free moment devoted to studying, his mind seemed saturated with information when he went to bed so that he found it very difficult to get to sleep at all.
As I established in this answer, the exams began in early June. Thus, Fred and George left school in May, which would have been shortly after their eighteenth birthday in April.
In Chapter Twelve of Order of the Phoenix they describe that year as their seventh and last year (my emphasis):
“We seriously debated whether we were going to bother coming back for our seventh year,” said George brightly, “now that we’ve got —”
He broke off at a warning look from Harry, who knew George had been about to mention the Triwizard winnings he had given them. “— now that we’ve got our O.W.L.s,” George said hastily. “I mean, do we really need N.E.W.T.s? But we didn’t think Mum could take us leaving school early, not on top of Percy turning out to be the world’s biggest prat.”
“We’re not going to waste our last year here, though,” said Fred, looking affectionately around at the Great Hall.