These two elves are Elrond's sons. We learn in The Fellowship of the Ring that they frequently ride with the Rangers of the North hunting orcs. So it's not surprising that they are good friends with Aragorn. After all, Aragorn is the chief of the Rangers of the North. And of course, he is also desperately in love with Elladan and Elrohir's sister, Arwen. When Aragorn calls on his Rangers to come help him fight the Haradrim, Elladan and Elrohir tag along to lend a hand.
Legolas tells us that Elladan and Elrohir are "fair and gallant as Elven-lords; and that is not to be wondered at in the sons of Elrond of Rivendell" (5.2.38). So at least Aragorn is riding into battle with some eye candy alongside him. Later, the narrator describes the two elves as "so much alike" that "few could tell them apart: dark-haired, grey-eyed, and their faces elven-fair, clad alike in bright mail beneath cloaks of silver grey" (5.2.57). We certainly can't tell them apart; they have no character differences at all that we can see.
In many ways, the The Lord of the Rings is a story obsessed with inheritance. Frodo inherits the Ring and all of its troubles from Bilbo, and Aragorn inherits his nobility of character and his right to the throne of Gondor from his ancestor, Isildur. They both get involved in the War of the Ring in the first place because of their family heritages.
So by the logic of this novel, it only makes sense that Elladan and Elrohir, the heirs of Elrond, would ride alongside Aragorn, the heir of Isildur, since Elendil, Isildur, and Elrond all fought together as part of the Last Alliance in the first war against Sauron. The next generation is continuing their fight.
In The Return of the King, as Aragorn's responsibilities grow, he needs more background helpers to support him. Elladan and Elrohir don't have a lot of character depth, but they do appear a lot in The Return of the King's Aragorn scenes because they're part of the king's posse.
So, it's Elladan and Elrohir who bring Aragorn advice from Elrond on where to go next as he rides away from Isengard. Elrond tells him, "The days are short. If thou art in haste, remember the Paths of the Dead" (5.2.25). Aragorn is not eager to take "that road" (5.2.26) (for obvious reasons, since the Dead are scary), but thanks to the convenient appearance of Elladan and Elrohir at just the right moment, Aragorn decides to go.
Once Aragorn gets to the gates of Minas Tirith, he gives the heirloom Star of Elendil to Elladan and Elrohir to hang onto until he is ready to take his official place as king. They also join him in healing the Black Shadow at the Houses of Healing, since they have some of Elrond's healing power.
When Aragorn leads the assault on the Black Gate of Barad-dûr to act as a decoy for the Ring-bearer, Elrohir tells him this is the whole reason they came to join him: "From the North we came with this purpose, and from Elrond our father we brought this very counsel. We will not turn back" (5.9.72). So Elladan and Elrohir wind up riding with five hundred horsemen into battle with Mordor, including the Grey Company of Rangers and the swan-knights of Dol Amroth. Seriously, they are just all over the place in this book, even though they are pretty flat as characters. And of course, they are there in the background as their sister, Arwen, finally marries her man.