You can approach this in two ways. One, you can perform the parent-child subquery and check the size()
of the returned list in Apex:
List<Account> accounts = [SELECT Id, Name, (SELECT id FROM Contacts), (SELECT id FROM opportunities) FROM Account];
for (Account a : accounts) {
System.debug('Count of Opportunities is ' + a.Opportunities.size());
System.debug('Count of Contacts is ' + a.Contacts.size());
}
n.b. this is an expensive query to run without filters and highly likely to run you into some kind of limits trouble or another.
or two, you can perform an aggregate query against each child object individually:
SELECT count(id), AccountId FROM Opportunity GROUP BY AccountId
SELECT count(id), AccountId FROM Contact GROUP BY AccountId
Both of which will return a list of AggregateResult
objects including the Account Id and the count of the child object specified that's linked to that Account.