I wanted to ask what is the best way to ask for forgiveness from Allah? How do we know that He has forgiven us especially if one is still in a lot of problems? How do we know that these problems are not punishment from Him?

Taubah is not just saying astaghferullah but it is procedure as per the Hadith of Rasul saw
The Prophet (SAWA) said, ‘Sincere repentance is remorse for the sin as soon as it slips out from you; then you ask Allah for forgiveness, then you never return to it.’
Sincere repentance is not to repeat the sin in future.Allah is all forgiving and He is kind.
I recommend you to pray to Rakat salat with the niyat that I'm praying two Rakat salat for taubah qurbatan ilallah.pray like morning prayer then recite astaghferullah Rabbi Wa atubu elaih 70 times followed by dua e Taubah of Imam Zainul Abedin as
Kindly read translation also to understand the words and concept of Taubah.
May Allah remove the burdens and resolve your problems.
Aameen
How one cane understand that it is punishment or test as Imam Ali as said if it make you closer to Allah then it is test if keep you away from Allah that means it is punishment.
If one blame Allah for the Difficulties that means it is punishment if he blamed himself means it is test.
How one can understand that his Tauba has been accepted if that person refrain from sin means it was accepted if still engage in disobedience that means taubah was not accepted