If the candidate wins the election but is never sworn in and dies, who is chosen and how?
According to the National Archives:
"If a winning Presidential candidate dies or becomes incapacitated between the counting of electoral votes in Congress and the inauguration, the Vice President elect will become President, according to Section 3 of the 20th Amendment."
Section 3 of the 20th Amendment is as follows:
"Section 3. If, at the time fixed for the beginning of the term of the President, the President elect shall have died, the Vice President elect shall become President. If a President shall not have been chosen before the time fixed for the beginning of his term, or if the President elect shall have failed to qualify, then the Vice President elect shall act as President until a President shall have qualified; and the Congress may by law provide for the case wherein neither a President elect nor a Vice President elect shall have qualified, declaring who shall then act as President, or the manner in which one who is to act shall be selected, and such person shall act accordingly until a President or Vice President shall have qualified."
As a general rule, if the president is is incapacitated (or dead as per your question), the Presidency defaults to the Vice President.
Horace Greeley actually did die before the electoral college votes were counted in 1872. Some of his electors voted for different candidates. Some voted for him. The ones that voted for him were thrown out by Congress.
Ultimately it didn't matter in 1872. Grant would have won in a landslide even if a single candidate had gotten all Greeley's electoral votes. But this does provide a precedent if it would happen in the future. His electors were allowed to choose otherwise valid candidates. Votes for the invalid Greeley were tossed.
Note that if no valid choice gets a majority of the electoral college vote, the House would get to choose. It's a little complicated in that they are supposed to choose from among the three top candidates in electoral votes. It's not clear what would happen if they replaced a dead winner with a fourth candidate.
It depends when this happens ...
Between election day and the vote of the Electoral College on 14 December
The party the deceased represented is entitled to nominate a replacement. For states that penalize faithless electors, a vote for the nominated replacement is not "faithless" but any other vote is.
There is no obligation that this would be the vice-president-elect but it probably would be in which case a new vice-president-elect would have to be named.
Between the Electoral College vote and counting and confirmation by Congress in January
Note that since the passing of the 20th Amendment in 1933, this has been the incoming, not the outgoing Congress. Also, this happens at 1 pm on January 6 unless Congress sets a different time and date. There are rules on how all this is done and Constitutionally those rules are set by Congress. The current rules are technically non-binding because a current Congress cannot constrain a future Congress but every Congress since it passed has adopted the procedure in the Electoral Count Act of 1887.
Any member is entitled to raise objections to any state's electoral selection - "because they're dead" is a pretty sound objection. If both chambers agree to uphold the objection, Congress decides who to award those vote to or if they should simply not be counted. The person who receives the majority of votes is the President. At various times the Congress has interpreted this to mean the majority of all electors (270) which is the currently accepted position or the majority of counted votes - ultimately this is a determination for the Congress of the day.
If this vote doesn't not produce a winner then the Contingent Election procedures kick in. The members of the House vote and their ballots are counted 1 per state - exactly how is up to the House. If the vote is tied for President it is resolved by the House but if tied for vice-President its resolved by the Senate.
If this goes on so long that noon on Inauguration Day (20 January) has come and gone then the vice_President is acting President until it all gets resolved.
Normal Presidential succession applies.