a melon stem remains indefinitely.
the melons make the plot underneath them revert to normal dirt, so they most be tilled again manually. an individual melon yields 3-7 slices, which can be saved or converted directly to seeds (1 slice --> 1 seeds). a stem takes 10-30 minutes to grow apparently, dunno how long it takes a melon to spawn - but they often don't take long at all.
not possible to make them self-sustainable, unfortunately. something to bear in mind is a melon slice only heals 1 unit of hunger, but requires much less time investment than wheat - 1 melon produces a minimum of 3 slices (3 units of hunger), but it takes 3 wheat to produce one bread (2.5 units)
pumpkins cannot be grown at this point in the game, pumpkin seeds do exist but do not actually spawn in chests, I guess? only obtainable by inventory hacking at this stage.
They are apparently a similar (but not identical) process, though.