The word "elegy" comes from the Greek word "elegeia" where it originally referred to any verse written in "elegiac couplets," but it has come to mean any mournful or sad poem, particularly a lament for the dead. Any sad poem can be called an elegy at the poet's discretion.
If a poet wished to write a traditional elegy, he might want to consider the classical form of the verse. An elegiac couplet is a pair of sequential lines where the first line is written in "dactylic hexameter" and the second line is written in "dactylic pentameter." A "dactyl" is a metrical "foot" consisting of one stressed syllable followed by two unstressed syllables. Hexameter and pentameter mean a six-footed line and a five-footed line, respectively. As with all poetry, small variations in the meter are allowed and even encouraged so that the verse does not become tedious or formulaic. Whatever the meter, a poet wishing to write an elegy would do well to study some of the famous examples available, such as Auden's "In Memory of W.B. Yeats," or Housman's "To an Athlete Dying Young," or E.E Cummings' "my father moved through dooms of love." "O Captain! My Captain!" is another famous example of an elegy, written by Walt Whitman to honor the slain Abraham Lincoln.