Timeline?: After World War 2 (1954).
Why does he dream of World War 2?: He was there.
There is some serious debate still raging in many deep, dark corners of the Internet about exactly what happened in the film. This is my take on events. Some of this is clearly true, whilst other bits are just opinion:
Andrew Laeddis fought during World War II and, like many, returned home as a war hero to his wife, Dolores, and his three* kids. However, his wife Dolores was mentally unbalanced. Some of the flashbacks and images in the film seem to suggest Andrew knew this. Possibly PTSD after the war caused him to be distant and he didn't realise how unbalanced she was until it was too late, or possibly there's some other reason we don't know of that he didn't notice. Either way, Dolores tragically murdered the three* children. In retaliation, Andrew killed her.
Due to the colossal grief, shame, confusion and anger felt after all these events, Andrew created a second person: Teddy. Teddy is still a war hero interestingly (that part hasn't been forgotten by Andrew), and he has carried on this hero status by becoming a Federal Marshall. He's on a hunt throughout Shutter Island to uncover and solve the mystery of patient 67 at the hospital.
However, he is really a part of a massive game on the island, orchestrated by his two doctors - Cawley and Sheehan. The island he is on is a psychiatric institute and he's been there ever since becoming mentally unbalanced himself after killing his wife. On the island, there are effectively two main practices. Patients are either "cured" or lobotomized. Some members of staff prefer the former (like the two doctors), whilst others prefer the latter.
The movie is all Cawley and Sheehan's way of trying to cure Andrew and make him realise he is not really this Teddy character.
All the above has mostly been my own opinion, but I can't resist referencing this article at ScreenRant which describes the ending, as I think they sum it up beautifully:
Teddy wakes up to the reality that he is actually Andrew Laeddis,
though he is warned by Dr. Cawley and Dr. Sheehan that he has
regressed into his fantasy world before. However, Andrew is smart:
When Dr. Sheehan sits with him on the steps that next morning, Andrew
knows that the doctors and Warden are observing his behavior. The
thing is, his guilt and pain are still so heavy that he knows he
cannot live with them; rather than live with the knowledge of his
pain, he chooses to pretend that he is still Teddy Daniels and let
them lobotomize him, so that he can finally be free of his burden.
That’s what the line to Dr. Sheehan about ‘living as a monster, or
dying as a good man,’ means – Andrew would rather be mind-wiped as
“Teddy Daniels” than live with the sins of Andrew Laeddis. The End.
Hopefully that provides some form of answer to your questions. The movie takes place some time after WW2. He dreams of WW2 because he was there - however how much of the timeline is actually real or imagined is very difficult to figure out. This is my own subjective take, so feel free to leave comments to agree/disagree.
*This answer originally referred to the two children, as the original asker's question did. However, there were three children and so the answer has been updated.