The authorities differ if the preferential time to light is at the beginning of the sunset or at the end which is when the stars come out.
A person can light even beforehand from the time of Plag HaMincha as long as the candles will burn till the end of the prescribed time. It is even permissible to light throughout the whole night, but should only make the blessing if there are other family members who are awake.
On Erev Shabbat, the Menorah should be lit before the Shabbat candles and they should burn for at least a half an hour after the stars come out. On Motzoei Shabbat, the authorities argue whether Havdala has precedence or the Menorah, and everyone should follow the custom of his ancestors.
Those that do not perform labor till the end of Shabbat according to Rabeinu Tam (approx. 72 min. after sunset) should light the Menorah at this time. Some authorities differ on this issue whether the custom is to act in accordance with the strict interpretation of the law, or just to further himself from doubt as to when is the correct time.