Towards the end of Transformers 4 Optimus Prime flew towards deep space without a ship, while in Transformers 3, the Autobots needed a big ship to travel to moon.
How is he able to do it? Was he upgraded?
The best guess is that Optimus obtained the rocket boosters when he pulled the sword of the Knights' Temenos from Lockdown's ship in the final act.
After pulling the sword where he said:
Recognize one of your Knights.
He gained armor and most likely other upgrades (such as whatever allowed him to KO Grimlock with a right hook).
This is the 2nd form we see Optimus in during the movie. The 1st is the junker truck.