Sure --
Ronald Reagan is one example, he ran for the Republican nomination in 1976 but lost to Gerald Ford, who then lost the general election against Jimmy Carter. Reagan would run again and take the nomination in 1980, then go on to win the Presidency in the general election against Carter, who was running for a second term.
There are also Presidents who lost the general election in one year, then would go on to win later -- Republican Richard Nixon, losing to Democrat John F. Kennedy in 1960, then winning against Democrat Hubert Humphrey in 1968.
There are also candidates who lost the general election, then were re-nominated and once again lost the next general election: Adlai Stevenson II against Dwight Eisenhower in 1952 and 1956.