In many problems assuming firms maximize their profit (i.e. maximize their profit function) is a good first assumption. However, it fails when there are agency problems and informational asymmetries are too high (and in some other cases as well). This being said in most problems that would be the first assumption I would try to model with before trying something else. To use a physics analogy I would compare it to having Newtonian and Relativistic physics, in that Newtonian physics is flawed but in many cases gives you reasonably accurate predictions (except probably profit maximization being social theory is not as accurate as Newtonian physics).
First, firms can’t actually maximize the profits in a sense that they take their profit function $\Pi = PQ -C(Q)$ they take the first order derivative to get FOCs and find $Q^*$. I don’t know of any firm that would do that and if someone knows an example I would like to see it.
Profit maximization is a metaphor for an ‘evolutionary’ pressure for profit maximization. Firms that don’t tend to maximize their profits tend not to survive. It’s similar to evolutionary biology that often uses game theory and will assume that let’s say pigeons are rationally maximizing calorie intake and chance to pass on genes which is of course not literally true (I somehow doubt that pigeons have mental faculties for calculus), rather the model is metaphor that gives good predictions for the animal behavior.
This is because modern economic methodology is heavily influenced by instrumentalism. Instrumentalism is epistemological idea that it does not matter if theory is literally true as long as it gives accurate predictions (eg see Friedman 1953).
However, this model won’t be always accurate. One of the most common reason for this you will find in textbooks are agency problems.
Many firms are not run by owners (principals) but agents (managers). Shareholders typically can’t see into the firm as well as CEO. Hence there is informational asymmetry between what CEO knows and what principal knows.
As a result this informational asymmetry can be exploited in a way that manager maximizes her or his utility as opposed to profit. For example, manager might have preference for leaving behind a legacy of building large firm so manager might push firm to expand beyond what’s profit maximizing (ie see empire building).
Moreover, because profit function is nearly impossible to observe (firms can’t really easily measure all their costs not even mentioning deriving whole cost function). As a consequence they can choose to maximize sales revenue instead of profit, or they might maximize sales revenue with profit constraint (eg see picture below from this source).
As you can see the sales maximizing with profit constraint is not always that far from profit maximizing, so in some cases using this model does not give significantly different predictions but it certainly can.

Above I gave two common alternatives to pure profit maximization. Of course there are more alternatives.
Going back to your main question:
My question is: Is profit maximization generally a good assumption for analyzing the behavior of a firm?
As argued above that is context dependent. Profit maximization is certainly good first assumption when you explore topic. It’s very common assumption still used in many theoretical papers published in top journals such as AEA Microeconomics field journal.
However, as argued above it is certainly not innocuous assumption. There are situations where assuming profit maximization won’t deliver correct predictions and other situations when it will be highly inaccurate. Listing all possible contingencies when this might happen is not feasible but above mentioned reasons are in my estimation the most common ones.
Ideally you should explore the past literature on a topic you are interested in and see if there are any arguments in favor of using alternative theories. If you are building some model where you are not sure about this I would not hesitate using profit maximization as first assumption but ideally you would want to compare predictions of such model to real world observations and if they fail try if other theory would work better.