Subaru Outback - gear shifting and engine stalling

2005 Subaru Outback - Driving on a highway, at speed above 40 mph, the gear suddenly shifted with a jerk and the check engine light (steady) came on, with the cruise light blinking, the car began loosing speed rapidly. Waited for about an hour. The check engine light went off and the car started and gained speed normally. Keeps happening. Any suggestion on what might be the problem ?

It could be a lot of different things. Anything we say here would be speculation.
The cruise light blinking happens when the check engine light comes on.
Bring the car to pepboys or autozone as they can check your codes for you for free. Whenever the check engine light comes on, it stores the condition that caused it, even when the light goes back off.
Then report back here with those codes.