Which sentence is more formal?

 - The senator announced unexpectedly that she was resigning.
 - Out of the blue, the senator announced that she was resigning.
The first sentence is less formal. You can tell because it uses an idiom (out of the blue).
The second sentence uses formal language in place of the idiom, so it is more formal overall.