If the rebel player has not revealed their base before the beginning of combat, and the system it is on is unoccupied, it is a valid retreat location. This is true regardless of which player's turn it is or whether or not units involved in the combat came from the rebel base.
Justification
The rules for retreat state:
A player must choose to retreat to a system that contains his units or
one of his loyalty markers, if able. He cannot retreat to a system
that contains his opponent’s units.
If there are no adjacent systems containing his units or loyalty markers, he can retreat to any adjacent system that does not contain
units.
A player cannot retreat to a system that his opponent moved units from to initiate the combat
Meanwhile, the rules for the rebel base state:
The “Rebel Base” space is not a system.
When Imperial ground units move into the system, the base is revealed
after all movement is completed, before resolving combat.
The Rebel player may optionally reveal his base at any time during one
of his turns of the Command Phase
Since the rebel base is not a system, units coming from it to participate in combat do not change the situation since units must come from a system to impose a retreat restriction ("A player cannot retreat to a system that his opponent moved units from").
Also as a result of the rebel base not being a system, as long as it is unrevealed, it does not change the retreat eligibility of the system on which it is hidden. If the rebel base is not revealed and the system on which it is hidden is unoccupied and neutral, then it is a valid retreat location for the empire (so long as there are no imperial systems adjacent to the battle).
If the empire retreats with ground forces, the base is revealed as a a result of having imperial ground forces there and a second battle will ensue. If the empire still has some forces (such as tie fighters or other ground troops) in the first battle location, the first battle should be concluded before beginning the second rebel base battle.
If the rebels initiated the combat next to their base however, things get a little more complicated because this combat occurs during the rebels' turn. One consequence of this is that if the empire retreats to the rebels base, the rebels will go first in the resulting combat because it is still their turn (despite the fact that the empire was the one that moved the units that initiated combat). But more importantly, on the rebels' turn the rebels can reveal their base before initiating combat to prevent it from being a valid imperial retreat location.
Note that the July 2016 FAQ errated away the very problematic "at any time" phrasing in when the rebels could reveal their base. It now reads:
If the Rebel player wishes to optionally reveal his base, he can only
do so at the start of one of his turns of the Command Phase, before
using one of his leaders.
If the rebels do not reveal their base before attacking an imperial fleet next to their base, however, the empire can still retreat to their base's system.
Aside
Before the errata to when the rebels could reveal their base, the "at any time" clause lead to a glaring timing question, with two possible interpretations:
By the point at which the empire has declared a retreat to the rebel base, it will happen; if the rebel player wants to prevent the empire from retreating to the rebel base, they must reveal the base before the empire declares their retreat.
If the empire declares a retreat to the rebel base, the rebel player can chose to reveal the base in response and invalidate the retreat.
The original rules didn't clarify on this point, but drawing on timing philosophy from other games actually leads to the same result as the errata gives us.
There are two primary philosophies for timing conflicts in games: stacks (such as in Magic the Gathering) and priority queues (like Android Netrunner). In a stack system, a player can use an "any time" action to respond to another player's action and the responding effect happens first. Stacks are "last in first out". In a priority queue system, players can only have their action happen first if the rules specifically define it as superseding the other player's action (such as preventing damage in Netrunner), and otherwise it resolves after. Queues are "first in first out", unless one thing is given preference by a specific rule.
The rules of Star Wars Rebellion give a lot of clear indicators that it is a priority queue game in terms of timing. Every part of the game where players interact, there is a defined order for the action, the reaction, and the resolution. Even with combat tactics cards, there is a separate step during which the recipient of damage gets to play damage block cards, meaning even one of the most classic interrupting actions (blocking damage) must be played in its specific order defined by the rules. The conclusion of this is that option 1 (defined above) is the case; if the rebels want to prevent the empire from retreating to the rebel base, they must reveal their base before the empire decides where to retreat. The errata supports this theory by specifying a time in the turn order when the rebels can reveal their base that is distinctly before any other actions that would be impacted by this.