I would say 1954 as it is more economical, but if you have lots of numbers in you MS it may start to read like a data sheet. In which case use words. It actually does not matter which you choose as long as you are consistent.
In dialogue I'd go with "nineteen fifty-four". If it wasn't in dialogue I'd prefer "1954", but I don't think there's a rule about this. Not sure.
I don't know if there is a rule for this but here is how I might approach it: I would absolutely use "nineteen fifty-four" if you are doing something official (such as a kind of public declaration: "In the year of our lord nineteen fifty-four...."). I would also suggest using "nineteen fifty-four" if you are dealing with an older historical setting, where formality and quality is valued over efficiency, as using "1954" may come off as more modern, informal and popular usage. Using the combination of letters and numbers is sort of half way to text language, such as using "h8" in stead of "hate" because our obsession with efficiency (in reducing the number of buttons you press or the amount of space used on the page) over-rides everything else. If it's poetry, I'd use nineteen fifty four as well. Given that Poetry is almost musical like singing, the rhythm of the words matters, so using nineteen fifty four gives you a better indication of the rhythm of the language than "1954" which doesn't suggest a clear rhythm in how you say the words themselves. (This could also apply to writing a screen play for basically the same reason). As far as I can tell, I'd use "1954" in basically every other context, including writing essays about historical events.
The rule as I learned it, and I've read this as an adult as well, is that dates are written in numbers, not words: December 25th, 1954 (or however it's written from one country to another.) That's the way you see it in novels, and it shouldn't change just because it's in dialogue. Like most things, the spelling stays the same in or out of quotes. The only exception would be if you want to let the reader know that someone pronounced the words differently, as in "in the year nineteen-hundred and fifty-four."
You use numbers for years even in dialog. Sure, writers have the creative freedom to play with this some, but if/when you sell your story, the editor will likely change it to numbers if you decide to go the other way.
It's a tough call. It depends, I think, on how you want the cadence to be as the reader reads it. That's especially critical for recent dates: 2010 could be spoken as "twenty-ten" or as "two thousand ten," depending on who's speaking, and two whom. There's a real argument for spelling it out in those contexts.