My question is what is the algorithm that a miner picks a transaction from the mempool to include it to a block?
Is it a greedy algorithm which just picks the ones with highest fees?
If it is not their own transactions, they will be greed and prioritize transactions with highest fee rates from tip of mempool first. In other words, they can proceed their own transactions with zero or very low fees.
Is the "age" of a transaction in the mempool also a factor? Or is it just a combination of fee and a random choice?
There are many mempools, not only one mempool. Each mempool has its own capacity and own settings. They can drop pending transactions from mempools after 1 day, 3 days (72 hours) or 14 days. It depends on their random settings.
Setup guidesDrop pending transactions with low fee after 72 hours, max mempool is 300 MB.
mempoolexpiry=72
maxmempool=300