We don't have enough information without knowing the account balances, but generally the process for closing accounts is done in four steps:
1. Close the revenue accounts: transfer the credit balances to a closing/summary account
2. Close the expense accounts: transfer the debit balances in the expense accounts to the closing/summary account
3. Close the summary account: transfer the balance of the summary account (which uses the two earlier steps) into the Retained Earnings account
4. Close the dividends account: transfer the debit balance of the dividends account into the Retained earnings account.