A person can only be the Prime Minister or a minister if they are a member of parliament. So, if the Prime Minister or a minister lost their seat in an election they would no longer be a member of parliament.
The Prime Minister is the leader of the government and is chosen by a vote of the members of the government. The Prime Minister keeps their job as long as they are a member of parliament and retains the support of the government. If the Prime Minister lost their seat at the next election, their party would need to elect a new leader.
This happened in 2007, when the then Prime Minister, John Howard, was not re-elected to his seat. His party then needed to elected a new party leader who became Leader of the Opposition (since the party also lost the election). Since federation in 1901, only two serving Prime Ministers have lost their seats at an election. The other was Stanley Melbourne Bruce in 1929.
Ministers are members of parliament and are appointed by the Prime Minister. If a minister lost their seat, the Prime Minister would need to appoint a new minister.