In-universe answer:
It seems quite plausible that Elsa is descended from someone who was cursed by ice magic.
That power may have then transferred down the family line.
As you can see from the image below, the King's library has a book detailing the risks of being hit by ice powers.
In this book we see a picture of a man being cured by trolls.
The runes next to the picture state that his condition was caused by being... " ...
to stone brought forth (by) powers of the moon sky " presumably in much the same way that Rapunzel's powers relate to a drop of sunlight falling from the sky.
Given the fine clothes he's wearing and the royal crest on his tunic, it's quite possible that he is of noble birth and hence, an ancestor of Elsa's.
Assuming some of the residual 'ice magic' was left in this man's system after he was cured
it would explain why one of his descendants was born with those same ice powers.
Out-of-Universe answer: Screenwriter Jennifer Lee specifically spoke to this point in an interview with Scriptnotes.
The origins of Elsa's powers (planetary alignment, predestination, etc) were intentionally obscured in order to simplify the story.
In a nutshell, she has powers because the plotline requires her to have powers .
Jennifer: And that there’s a connection between them, but
yet it’s not in your face, but it’s just something that… — Because what I always loved about, particularly Pixar films for me, was that everything just added up.
And everything had a special little, “Oh my god, oh my god, wait, and that, and that!”
And it was my favorite thing and we wanted to make kind of every time we had a scene trying to say what is that that’s maximum, why is it here.
If there’s anything extraneous we got to get rid of it.
But yet adding all that flavor, so that’s why.
But to move onto Elsa, it was an exhausting process coming to the simplicity of her powers.
At times we had a narration by a troll, who used to have a Brooklyn accent for no reason other than I miss Brooklyn.
You know, no reason.
But, we had this whole explanation like when Saturn is in this alignment with such-and-such on the thousandth year a child will be born and blah, blah, blah.
And then – John:
Ultimately you almost throw it away with one line.
So, the line is just like, “Was she born with the powers or was she cursed?.
And it’s born with it and that’s the last piece of it.
Aline:
It’s so great.
Jennifer:
And that’s it.
But I think part of what it was is if anything about us felt like it was like, “Oh, god, like okay, we have to say this,” then we didn’t want to say it.
And then also we found the more you explained the more questions you had about magic and the rules.
It was like, argh.
You know?
scifi.stackexchange.com/users/20774/Valorum
When they visit the trolls, the Grand Pabbie asks "Born or cursed?"
Elsa's dad answers "Born."
Aside from this, there is no other reference to how she got her powers.
Here's a link to the screenplay.
On page 6 is where they visit the trolls.
EDIT AFTER FROZEN
2 RELEASE:
Elsa was given her powers by the spirits in the North so that she could right the wrongs committed by her grandfather, and calm the angry nature spirits.
scifi.stackexchange.com/users/11159/PiousVenom
Frozen is cited as being inspired by Hans Christian Andersen's The Snow Queen .
However, the link seems pretty loose, and the titular Snow Queen's powers don't seem to have a specified origin beyond simply being her nature.
Furthermore, Elsa's character doesn't really bear any resemblance to the character of the Snow Queen, and in general there is very little similarity between the plots.
As MyCodeSucks points out, the only reference to the power's origin in Frozen is that Elsa was born with it.
scifi.stackexchange.com/users/1359/Beofett
Here's a quick summary of the history we learn from Frozen 2:
There was a group of people called the Northuldra living in an enchanted forest to the north of Arendelle.
These people had a great connection to magic, living and working with the four elementals (water, fire, earth, and air)
up until the elementals were upset by conflict between the Northuldra and the Arendellians, which was started by Elsa and Anna's paternal grandfather, King Runeard of Arendelle.
(Then) Prince Agnarr is saved by one of the Northuldra, Iduna, who becomes his wife (and of course they are Elsa and Anna's parents).
As for what this makes Elsa:
Elsa is the fifth elemental, born with her powers as a gift from nature due to her mother selflessly saving her father.
She is destined to be a bridge between the mundane and magical worlds.
Which means that her powers aren't from a curse after all.
scifi.stackexchange.com/users/82909/Laurel
The Grand Pabbie asks Born with the powers or cursed? and the King immediately says Born.
And they're getting stronger.
However, when Anna tells Elsa that her ice powers have set off an eternal winter "everywhere", Elsa loses hope and sings,
Oh, I should have known, I can't be free/
No escape from the storm inside of me/
I can't control the curse/Anna, please, you'll only make it worse!
Basically, Elsa calls it a curse because she sees it as one, but it isn't; she was born with it.
scifi.stackexchange.com/users/35506/Gothelittle
I recently saw the movie  Frozen , and got to wondering about Elsa's amazing Ice Powers.    Where exactly did they come from?  It's apparent that there's some type of curse from the dialogue between her parents and the Trolls, and possibly that it's an inherited curse from her father's knowledge of how to control it by wearing gloves, but does anything beyond that indicate how Elsa (and possibly the whole family) came to be cursed this way?
Is it ever explained where Elsa got her powers?
scifi.stackexchange.com
<disney><frozen>
scifi.stackexchange.com/questions/58489
scifi.stackexchange.com/users/20533/Zibbobz
Elsa was not cursed with her powers, but born with them. Elsa was given her powers as a gift from nature by the spirits in the North so that she could right the wrongs committed by her grandfather, and calm the angry nature spirits. Elsa got her powers from her mother.
Elsa got her powers from her mother.