Was John the Baptist Elijah? John 1:21 and Matthew 11:14 appear to give different answers to this question.
To begin, the Lord had promised Israel that He would send them Elijah the prophet before "the coming of the great and terrible day of the Lord" (Mal. 4:5). When the Jews saw John, and heard his preaching, they clearly wondered if he might be the promised figure of Elijah. But why?
First, as Edwin Blum points out in his commentary on John, "John had an Elijah-type ministry. He appeared on the scene suddenly and even dressed like Elijah. He sought to turn people back to God as Elijah did in his day" (The Bible Knowledge Commentary, eds. John Walvoord and Roy Zuck [Victor Books, 1983], 274). Thus, when the Jews saw someone who dressed like Elijah and had a similar ministry as Elijah's, they rightly wondered whether he might in fact BE Elijah.
But John said he was not Elijah. And, as you pointed out, this seems odd because in Matt. 11:14 Jesus says of John, "And if you care to accept it, he himself is Elijah, who was to come." So what's going on here? Charles Ryrie comments on this verse, "Jesus is saying that if the Jews had received Him, they would also have understood that John fulfilled the O.T. prediction of the coming of Elijah before the day of the Lord" (Ryrie Study Bible, 1463). But of course the Jews did not receive Jesus at His first coming. Indeed, in the next chapter (Matt. 12) there is clear evidence of the rejection of Jesus by the Jewish religious establishment (vv. 22-45). Afterward, Jesus began to veil His message in parables (see Matt. 13:10-15). And later still, after the Transfiguration when the disciples ask Jesus why the scribes say that Elijah must come first, Jesus responds by saying, "Elijah is coming and will restore all things; but I say to you, that Elijah already came, and they did not recognize him, but did to him whatever they wished." Then the text goes on to say, "Then the disciples understood that He had spoken to them about John the Baptist" (Matt. 17:10-13).
Here's what I think is going on. John the Baptist would have served as the fulfillment of God's promise to send Elijah before the day of the Lord (Mal. 4:5) IF the Jews had received Jesus as their Messiah. They did not, however, and so, as Jesus makes clear in Matt. 17:11, Elijah is still to come. Indeed, some commentators believe that one of the two witnesses mentioned in Rev. 11:3 may be "Elijah". Of course, as in the case of John the Baptist, this does not necessarily mean the literal, historical Elijah, but simply someone who comes in the spirit and power of Elijah and performs a similar ministry. At any rate, this is how I think we should understand the Baptist's response in John 1:21. He is led to deny that he is Elijah because God already knows that the Jews would reject His Son. Hence, as Jesus later affirms in Matt. 17:11, Elijah is still to come.
Hope this helps. God bless you!