Yes and No.
True Polymorph is a powerful tool, but it does have limitations. One such limitation is that it is only able to transform something into a creature which has a Challenge Rating.
the new form can be any kind you choose whose challenge rating is equal to or less than the target's (or its level, if the target doesn't have a challenge rating)
Targets of the spell are thus limited to becoming creatures with stat blocks, such as those found in the Monster Manual. With that established, your questions can be answered like so:
Yes, a spellcasting monster can learn/prepare different spells.
The Monster Manual introduction (Special Traits > Spellcasting) states the following:
You can change the spells that a monster knows or has prepared, replacing any spell on a monster’s spell list with a different spell of the same level and from the same class list.
No, a spellcasting monster cannot cast spells as rituals.
The Player's Handbook (Spellcasting > Rituals) states:
To cast a spell as a ritual, a spellcaster must have a feature that grants the ability to do so.
There are no creature stat block traits (as far as I'm aware) which grant this feature, which means the rules as written prevent a monster from casting a spell as a ritual.
Of course, a DM is free to house rule the ability for certain monsters to be able to cast spells as a ritual, for the sake of verisimilitude. The Monster Manual even says that the traits in a stat block are only those which relate to combat or require some explanation, so the absence of a Ritual Caster trait might simply have been left off for not being combat-focused or complicated enough to merit inclusion.