I think they created the beginning and the end of the story from the very start of the series and then just made it up all the story in-between.
They knew that Jack was going to sacrifice and the rest of the survivors would finally leave the island. Only that their first the idea was that losties really died in the island. That's why Christian body was missing, why losties saw dead people around and the whispers. But the writers, after the feedback for fans thought it was so insulting to viewers that decided to create the flash sideways as a limbo. That's why they made Christian remark that everything in the island was real. It was a fail safe for the end when the writers made a real mess of the story.
The point is the ending was great, but it could have been so much better. They could have given us answers as well, if they really had any. They should have included Ab Aeterno and Across the Sea before in the series and make another episode of other Others arriving at the island in different periods, coming from Egypt, Mexico, Japan and other great civilizations. They built Tawaret statue, the temple and later the light house. It would have left less of the story to intepretation, but it would have been more fulfilling for us. And also I would have made another flashback episode called The Travellers, showing people from Atlantis arriving much before Jacob's and MIB's mother. They would be the builders of the cork! Fake mother would have been in that group and she could have been received some kind of divine message about the importance of the island and the light source and why she had to protect it. I would also have liked an episode called What The Numbers Are that would show the real meaning behind those numbers, but I guess they never had a real meaning after all. They are just numbers! Season 6 would have been much better if only it had a couple more of episodes giving answers.
Well, maybe the lack of answers isn't so bad after all, because we can continue creating theories like mine for a long time, but at the same time it would have made it much more interesting for fans in a logical level. For me they decided to create an ending somewhat related to those of Donnie Darko or 2001, where everyone can theorize about what really happened, but in a story so focused on mysteries, some solutions would have been welcome. Nonetheless it has been an amazing six year travel in a mysterious island and it has been great sharing ideas and the love for Lost!
Edited 2 total times.