2008 subaru impreza

2008 Subaru Impreza
Was riding fine when suddenly the check engine light flashed and it disabled the cruise control. As it was on the highway in early am with no open garages I got to my destination. It drove rough and is now driving smooth but the check engine light is now steady. Ideas and costs?